Posts

While & do while loop in C++

Image
 While in CPP . A  while  loop statement repeatedly executes a target statement as long as a given condition is true .  This is also a loop Structure , but is an enter-controlled one  Syntax: while( condition is true) {  action1; } action 2; Program : Write a program in CPP to count the number of alphabets ,digit and special Symbol                @#$%&)using while loop.  #include<iostream> using namespace std; int main() {           char  str[100];            int i=0 ,digit=0,alphabets=0,special=0,characters=0 ,count=0; cout<<"Enter the string :"; gets(str); cout<<"Enter string is "<<str<<"\n"; while(str[i]!='\0') { count++; i++; } i=0; while(str[i]!='\0') { if(str[i]>='0' && str[i]<='9') { digit++; } if(str[i]=='@' ||str[i]=='#' ||str[i]=='$' ||str[i]=='%'||str[i]=='^'||...

For loop in C++

Image
 For loop: The for is an entery entrolled loop and is used when an action is to be repeated for a predetermined number of times. Similarly When we have  executes same line of statement  repetitively is done by LOOP. Syntax: for(initial value; test; increment)        { action1; } action2; Program: Write a program to print 1 to 10 number using for loop . Code: #include<iostream> using namespace std; int main() { int i; for(i=1;i<=10;i++) { printf("%d\n",i); } } OUTPUT: 1 2 3 4 5 6 7 8 9 10 -------------------------------- Program2Write a Program in C++ to Print all natural numbers upto N without using semi-                                       colon(;) using for loop. Code: #include<iostream> using namespace std; int main() { int i , no; cout<<"Enter the number to print "; cin>>no; for(i=1;i<=...

If If....else statement in C++

Image
 If  in CPP if-block are executed only if -expression contain TRUE value. if statement consists of a  boolean expression followed by one or more statements. Syntax:    if (expression is true) {     action1; } action2; action3; Program: Write a program in C++ to find the greatest number in two numbers with the help of if Code: #include<iostream> using namespace std; int main() { int num1, num2;  cout<<"Enter the two number ";  cin>>num1;  cin>>num2;  if(num1>num2)  cout<<"Num1 is greatest number";  if(num2>num1)  cout<<"num2 is greatest number"; if(num1==num2)   cout<<"number are equal"; return 0; }   Output: Enter the two number 25 20 Num1 is greatest number -------------------------------- Enter the two number 10 32 num2 is greatest number -------------------------------- Enter the two number 10 10 number are equal -------------------------------- Q.n: What w...

Keywords Identifiers Constant in C++

Image
Keywords: The Keywords implement specific C++ language features. They are explicitly reserved identifiers and cannot be used as names for the program variables or other user-defined program elements. Many of Keywords are common to both C and C+.   Example:               break                     auto       case float If public short while Int Identifiers: Identifiers refer to the names of variables, functions, arrays, classes , etc. created by the programmer. They are the fundamental requirement of any language. Each language has its own rules for naming these identifiers. The following rules are common to both C and C++. ·          Only alphabetic charact...

Variables And Input operator in c++

Image
 Variables  Variable size                                                                                                                                                                           Variable provides us  to store the data in System with named witch further can manipulate. In C++  Variable has a specific type, which tell the size and layout of the variable's memory.  Program: write a program to find out the average of two number take input from user...

C++ language with code

Image
What is C++? C++ C++ is an object-oriented programming language. It was developed by Bjarne Stoustrup at AT&T Bell Laboratories in Murray Hill, New Jersey USA, in the early 1980’s. Stroustrup , an admirer of Simula67 and a strong supporter of C, wanted to combine the best of both the languages that could support object-oriented programming features and still retain the power and elegance of C.     C++ is a superset of C. Most of what we already know about C applies to C++ also. The   most important facilities that C++ adds on to C classes, inheritance , function overloading and operator overloading. These features enable creating of abstract data types, inherit properties from existing data type and support polymorphism thereby making C++ a truly object-oriented language.   Application of C++ ·          Since C++ allows us to create hierarchy-related objects, we can build special object-oriented libraries whic...

Array in C programming

Image
 Array  Array  Array is defined as an ordered list of homogeneous data element. May be of type int, float,char or double  All these element are stored in consecutive memory locations An array is described by a single name or an identifier and each element in an array is referenced by a subscript  enclosed  in a pair of square brackets. Arrays are of two types:           One-dimensional arrays           Multidimensional arrays Two dimensional array Three dimensional array Four dimensional array One Dimensional Array(1D)               Arrays must be declared before they can be used in the program. The dimensionality of an array is determined by the number of subscript present in the given array. If there is only one subscript, then it is called a one-dimensional array.  Syntax:               type variable_name[lengt...

Recursion function in C language

Image
 Recursion  A function is said to be recursive if it can be defined in the terms of itself. Recursion is a programming technique that allows the programmer to express operation in terms of themselves. In C, this take the form of a function that  call itself. Syntax:               void recursion() {                         recursion(); } Program: write a program to find out the factorial of  a number using Recursion function. Code: #include<stdio.h>                                                                        int factorial(int x)  {   if(x==1)   return 1;   else    return x*factorial(x-1);  ...

Output Function in C programming

Image
 C Output Function  C programming language provides built-in functions to perform output operation. The output operations are used to display data on user screen (output screen ) or printer or any file.  printf() function  The printf() function is used to print string or data values or a combination of string and data values on the output screen. Syntax:      printf("message to be displya"); program-Write a program to print "hello world " using printf(). Code: #include<stdio.h> void main() { printf("hello world"); } Output: hello world -------------------------------- we used    the printf() function to print a string on to the output screen  The printf() function is also used to display data values. when we want to display data values we use format string of the data value to be displayed. Syntax:                    printf("format string ", varaibleName); program: #include...

Types of functions in C programing language

Image
 Types of function  Types of function  program:- add two number with all categories i) Functions with no arguments and no return values. Syntax: function_name() { valid C Code; } code- #include<stdio.h> void sum() { int x,y,z; printf("Enter two no's "); scanf("%d%d",&x,&y); z=x+y; printf("sum of %d & %d =%d",x,y,z); } void main() { sum(); } Output- Enter two no's 95 36 sum of 95 & 36 =131 -------------------------------- ii) Functions with arguments and no return values  Syntax: function_name(argument1,argument2,- - - - - - -,argument n) { Valid C Code; } Code: #include<stdio.h> void sum(int x,int y) { int z; z=x+y; printf("sum of %d & %d =%d",x,y,z); } void main() { int x,y; printf("Enter two no's"); scanf("%d %d",&x,&y); sum(x,y); } Output: Enter two no's12 32 sum of 12 & 32 =44 -------------------------------- iii) Functions with arguments...