Posts

Showing posts with the label if-else

Program to test if/else

Image
  Program to test if/else

Prpgram to check if a number is even or odd

Image
  Prpgram to check if a number is even or odd

Program to find the maximum among the three numbers

Image
  Program to find the maximum among the three numbers

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 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 ; }