Posts

multiplication table

  #include <iostream> using namespace std; int main() { int n;     cout<< "Enter the number for which you want the table to be displayed: " ;     cin>>n;     cout<< "Table of  " <<n<< ":" <<endl;     for ( int i= 0 ;i< 10 ;i++)     { cout<<n<< " X " <<(i+ 1 )<< " = " <<(n*(i+ 1 ))<<endl;     }     return 0 ; }

switch case program in c++

  #include <iostream> using namespace std; int main() {     int a,i= 34 ;     //**********************control structures---if else if statements********************** cout<< "Enter an integer:" ; cin>>a; switch (a)     {     case 34 :         cout<< "\nYou guessed it right" ;         break ;     case 56 :         cout<< "\nYour guess is high" ;         break ;         case 23 :         cout<< "\nYour guess is low" ;         break ;             default :     cout<< "\nTry next time" ;                 break ;     }     return 0 ; }

if else condition

  #include <iostream> using namespace std; int main() {     int a,i= 34 ; cout<< "Enter an integer:" ; cin>>a;     if (a<i)     {         cout<< "Your number is less" ;             }     else if (a==i)     {         cout<< "Your guessed the right number" ;             }     else {         cout<< "Your number is greater" ;     }     return 0 ; }

constants,manupulators and operator precedence

  #include <iostream> #include <iomanip> using namespace std; int main() {     int a= 4 ,b= 56 ,c= 67 ; const int y= 9 ;     // y=10; it cannot happen as y is a constant     cout<< "The value of y is:" <<y; cout<< "\nThe value of ab is:" <<a;     cout<< "\nThe value of b is:" <<b;     cout<< "\nThe value of c is:" <<c; //********************manipulation operator*****endl and setw***************************     cout<< "\n\nThe value of a using setw is:" <<setw( 4 )<<a;     cout<< "\nThe value of b using setw is:" <<setw( 4 )<<b;     cout<< "\nThe value of c using setw is:" <<setw( 4 )<<c;     //***********************Operator precedence*******************************         int z= ((((a* 5 )+b)- 45 )+ 87 );     cout<< "\nThe value of z is:" <<z;     return 0 ; }

displaying how float, double and long double works in c++

  #include <iostream> using namespace std; int main() {     float a= 3.14 ;     long double b= 23.99 ;     cout<< "The size of 3.14 is:" << sizeof ( 3.14 )<<endl;//by default f is treated as double     cout<< "The size of 3.14f is:" << sizeof ( 3.14f )<<endl;     cout<< "The size of 3.14F is:" << sizeof ( 3.14F )<<endl;     cout<< "The size of 3.14l is:" << sizeof ( 3.14l )<<endl;     cout<< "The size of 3.14L is:" << sizeof ( 3.14L )<<endl;     return 0 ; }

taking input from user

  #include <iostream> using namespace std; int main() {   int num1,num2;     cout<< "Enter the value of num1:\n" ;     cin>>num1;     cout<< "Enter the value of num2:\n" ;     cin>>num2;     cout<< "The value of num1 is:" <<num1<< " and num2 is:" <<num2;     return 0 ; }

understanding built-in variables

  #include <iostream> using namespace std; int main() {     int a= 4 ,b= 5 ;     float pi= 3.14 ;     char c= 'a' ;     cout<< "The value of a and b is:" <<a << " and " <<b<< "\n" ;     cout<< "The value of pi is:" <<pi<< "\n" ;     cout<< "The value of character is:" <<c;     return 0 ; }