Posts

Showing posts from November, 2022

List

     LIST  Print hello world To print size of int, float, char, bool, shortint and longint. Program to print sum of two numbers. Testing string Testing string and line break.  To test chainability. Program to test if-else Program to find the maximum among the three numbers Program to check if a number is even or odd Program to test if-else (to check voter eligibility) Program to check if a triangle is scalene, isosceles or equilateral. Program to check if an alphabet is a vowel or a consonant. Program to find sum of natural numbers till n. Program to test loop-while Program to add only positive numbers. Program to display multiplication table upto 10. Program to test continue-break. Print number from 1 to 100, skip nos. divisible by 3 Program to print all the even numbers till "n". Using switch operator. Implement a single calculator using switch. Calculator - Output of division, addition, substraction and multiplication of two given numbers.

Calculator - Output of division, addition, substraction and multiplication of two given numbers.

ap3g #include <iostream> using namespace std ; //decimal output ke leye calculator jo sab sath mein hora(float). :D int main (){       float a , b ;       cout << "Input two numbers: " ;       cin >> a >> b ;       cout << "Output of division, addition, substraction and multiplication of two given numbers: " << endl ;       char op ;                               //if(op = '/'){             float div = a / b ;             cout << "a " << "/" << " b = " << div << endl ;          //}           //if(op = '+'){               float add = a + b ;               cout << "a " << "+" ...

Implement a single calculator using switch.

  ap3f #include <iostream> using namespace std ; //implement a single calculator using switch. int main (){     int n1 , n2 ;     cout << "Input two numbers: " ;     cin >> n1 >> n2 ;     char op ;     cout << "Input an operator: " ;     cin >> op ;     switch ( op ){         case '+' :         cout << n1 + n2 << endl ;         break ;         case '-' :         cout << n1 - n2 << endl ;         break ;         case '*' :         cout << n1 * n2 << endl ;         break ;         case '/' :         cout << n1 / n2 << endl ;         break ;         default ...

Using switch operator.

ap3e #include <iostream> using namespace std ; //Using switch operator. int main (){     char button ;     cin >> button ;     switch ( button ){                     case 'a' :           cout << "Hello" << endl ;           break ;           case 'b' :           cout << "Namaste" << endl ;           break ;           case 'c' :           cout << "Salam" << endl ;           break ;           case 'd' :           cout << "Hola" << endl ;           break ;           case 'e' :           cout << "Ciao" << endl ; ...

Program to print all the odd numbers till "n".

  ap3d #include <iostream> using namespace std ; //Program to print all the odd numbers till "n". int main (){     int n ;     cout << "Enter a number: " ;     cin >> n ;     cout << "All the odd numbers till " << n << " are:" << endl ;     for ( int i = 2 ; i <= n ; i ++){                     if ( i % 2 == 0 ){             continue ;          }           cout << i << endl ;     }     return 0 ; }

Program to print all the even numbers till "n".

  ap3c #include <iostream> using namespace std ; //Program to print all the even numbers till "n". int main (){     int n ;     cout << "Enter a number: " ;     cin >> n ;     cout << "All the even numbers till " << n << " are:" << endl ;     for ( int i = 1 ; i <= n ; i ++){         if ( i % 2 != 0 ){             continue ;         }         cout << i << endl ;     }     return 0 ; }

Print number from 1 to 100, skip nos. divisible by 3

ap3b #include <iostream> using namespace std ; //Print number from 1 to 100, skip nos. divisible by 3. int main (){             for ( int i = 0 ; i <= 100 ; i ++){         if ( i % 3 == 0 ){             continue ;         }         cout << i << endl ;      }       return 0 ; }  

Program to test continue-break.

  ap3a #include <iostream> using namespace std ; //Pocket money aur go out wala program. int main (){     int pocketMoney = 3000 ;     for ( int date = 1 ; date <= 30 ; date ++){         if ( date % 2 == 0 ){             //skips if satisfied and continues the loop.             continue ;         }         if ( pocketMoney == 0 ){             //This helps to break the loop and come out of it.             break ;         }         cout << "On date: " << date << " go out" << endl ;         pocketMoney = pocketMoney - 300 ;     }     return 0 ; }

Program to display multiplication table upto 10.

ap2m #include <iostream> using namespace std ; //Program to display multiplication table upto 10.(for loop) int main (){     int n ;     cout << "Enter a positive number : " ;     cin >> n ;       cout << "Table of " << n << endl ;     for ( int i = 1 ; i <= 10 ; ++ i ){         cout << n << " * " << i << " = " << n * i << endl ;     }     return 0 ; }  

Program to add only positive numbers.

  ap2l #include <iostream> using namespace std ; //Program to add only positive numbers.(while loop) int main (){     int number ;     int sum = 0 ;     cout << "Enter a number:" ;     cin >> number ;     while ( number >= 0 ){         sum = sum + number ;         cout << "Enter a number:" ;         cin >> number ;             }       cout << "Sum of all the positive numbers are " << sum << endl ;         return 0 ; }

Program to test loop-while

  ap2k #include <iostream> using namespace std ;  //program to test loop-while.   int main (){     int n ;     cin >> n ;     while ( n > 0 ){         cout << n << endl ;         cin >> n ;     }       return 0 ;  }

Program to find sum of natural numbers till n.

  ap2j #include <iostream> using namespace std ; //Program to find sum of natural numbers till n.(for loop) int main (){     int n ;     cout << "Enter number 'n' : " ;     cin >> n ;     int sum = 0 ;     for ( int counter = 1 ; counter <= n ; counter ++){         sum = sum + counter ;     }     cout << "sum : " << sum << endl ;     return 0 ; }

Program to check if an alphabet is a vowel or a consonant.

  ap2i #include <iostream> using namespace std ; //Program to check if an alphabet is a vowel or a consonant. int main (){             char c ;       int isLowercaseVowel , isUppercaseVowel ;       cout << "Enter an alphabet:" ;       cin >> c ;       isLowercaseVowel = ( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' );       isUppercaseVowel = ( c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' );       if ( isLowercaseVowel || isUppercaseVowel ){                     cout << c << " is a vowel." ;      }       else {           cout << c << " is a consonant." ;      }       return 0 ;         }

Program to check if a triangle is scalene, isosceles or equilateral.

ap2h #include <iostream> using namespace std ; //Program to check if a triangle is scalene, isosceles or equilateral. int main (){             cout << "Print the type of triangle. \n " ;       int sideA , sideB , sideC ;       cout << "Input Three Sides Of Triangle:" ;       cin >> sideA >> sideB >> sideC ;       if ( sideA == sideB && sideB == sideC ){         cout << "This is an equilateral triangle. \n " ;      }       else if ( sideA == sideB || sideA == sideC || sideB == sideC ){         cout << "This is an isosceles triangle. \n " ;      }     else {         cout << "This is sclene triangle. \n " ;     }     return 0 ; }  

Program to test if-else (to check voter eligibility)

  ap2g #include <iostream> using namespace std ; //Program to test if/else int main (){     int age ;     cin >> age ;         if ( age >= 18 ) {         cout << "You Can Vote." ;     }     else {         cout << "Not Eligible For Voting." ;     }     return 0 ; }

Program to check if a number is even or odd

  ap2f #include <iostream> using namespace std ; //Prpgram to check if a number is even or odd int main (){     int n;     cin>>n;     if (n% 2 == 0 ){         cout<< "Even" <<endl;     }     else {         cout<< "Odd" <<endl;     }     return 0 ; }

Program to find the maximum among the three numbers

  ap2e #include <iostream> using namespace std ; //Program to find the maximum among the three numbers int main (){     int a , b , c ;     cin >> a >> b >> c ;     if ( a > b ){         if ( a > c ){             cout << a << endl ;         }         else {           cout << c << endl ;         }         }     else {         if ( b > c ){             cout << b << endl ;         }         else {             cout << c << endl ;         }     }   return 0 ; }

Program to test if-else

ap2d   #include <iostream> using namespace std ; //Time pass program :) int main (){     //#ifndef ONLINE_JUDGE //NOT PART OF CODE USED TO MODIFY INPUT OUTPUT        //freopen("input.txt", "r", stdin);        //freopen("output.text", "w", stdout);     //#endif   cout << "Going out on a Date: \n " ; int savings ; cin >> savings ; if ( savings > 5000 ){     cout << "Very Sexy Man \n " ; } else if ( savings > 2000 ){     cout << "Sexy Man \n " ; } else {     cout << "Best Friend \n " ; }     return 0 ; }

To test chainability.

ap2c   #include <iostream> using namespace std ; int main (){     char ch ;     cout << "Press a character and press enter:" ;     cin >> ch ;     cout << ch ;     // to test chainability of following operator.     cin >> ch >> ch ;     cout << ch << ch ;     return 0 ; }

Testing string and line break.

  ap2b #include <iostream> using namespace std ; int main (){     cout << "Hello World, this is a test string. \n " ;     cout << "another test string to check line break." << endl ;     cout << "dekhne ke leye ki sab changa si ke nhi si." ;     return 0 ; }

Testing string

ap2   #include <iostream> using namespace std ; int main (){     cout << "Hello World," << "this is a test" << " string." ;     return 0 ; }

Program to print sum of two numbers.

  ap1 #include <iostream> using namespace std ; //Program to print sum of two numbers. int main (){     int amount1 ;     cin >> amount1 ;     int amount2 ;     cin >> amount2 ;     int sum = amount1 + amount2 ;     cout << "sum \n " ;     cout << sum ;     return 0 ; }

To print size of int, float, char, bool, shortint and longint.

ap0   #include <iostream> using namespace std ; int main (){     int a; //declaration     a= 12 ; //initialisation     cout<< "size of int" << sizeof (a)<<endl;     float b;     cout<< "size of float" << sizeof (b)<<endl;     char c;     cout<< "size of char" << sizeof (c)<<endl;     bool d;     cout<< "size of bool" << sizeof (d)<<endl;     short int si;     long int li;           cout<< "size of shortint" << sizeof (si)<<endl;     cout<< "size of longint" << sizeof (li)<<endl;     return 0 ;          }

Print hello world

#include <iostream> int main (){     std :: cout << "Hello World" ;     return 0 ; }