Posts

Showing posts from February, 2023

51: Write a program that displays your favorite poem. Use an appropriate escape sequence for the line breaks

  // Write a program that displays your favorite poem. Use an appropriate escape sequence for the line breaks #include < iostream > using namespace std ; int main () {     cout << " Wake up to reality! " << endl           << " Nothing ever goes as planned in this accursed world. " << endl           << endl           << " The longer you live, the more you realize " << endl           << " that the only things that truly exist in this reality " << endl           << " are merely pain, suffering and futility. " << endl           << endl           << " Listen, everywhere you look in this world, " << endl           << " wherever there is light, " << endl ...

50: ***(Syntax)*** Switch Statement

Switch Statement Syntax: switch ( expression ) { case /* constant-expression */ :     /* code */     break ; default :     break ; } Important points:   You cannot add inequalities like  percentage < 80  in the case of switch statement. You can use ranges in case like:  ' 0 ' ... ' 9 ' ' a ' ... ' z ' ' A ' ... ' Z ' If there is same output for various cases , you cannot do: switch ( alpha )     {     case ' A ' || ' a ' || ' E ' || ' r ' || ' I ' || ' i ' || ' O ' || ' o ' || ' U ' || ' u ' :         cout << " This is a vowel " ;         break ;         default :         break ;     } If there is same output for various cases , you can do:     switch ( alpha )     {     case ' A ' :     case ' a ' :     case ' E ' :     case ...

49: Write a program to check if a number is a multiple of 3 and 5.

  // Write a program to check if a number is a multiple of 3 and 5. #include < iostream > using namespace std ; int main () {     int num ;     cout << " Enter the number: " ;     cin >> num ;     if ( num % 5 == 0 && num % 3 == 0 )     {         cout << num << " is a multiple of 5 " ;     }     else         cout << num << " is not a multiple of 5 " ;     return 0 ; }

48: Write a program to check if a number is a multiple of 5.

  // Write a program to check if a number is a multiple of 5. #include < iostream > using namespace std ; int main () {     int num ;     cout << " Enter the number: " ;     cin >> num ;     if ( num % 5 == 0 )     {         cout << num << " is a multiple of 5 " ;     }     else if ( num % 5 != 0 )     {         cout << num << " is not a multiple of 5 " ;     }     return 0 ; }

47: Write a program to determine the minimum of two numbers

  // Write a program to determine the minimum of two numbers #include < iostream > #include < cmath > using namespace std ; int main () {     float num1 , num2 , mini ;     cout << " Enter first number: " ;     cin >> num1 ;     cout << " Enter second number: " ;     cin >> num2 ;     mini = min ( num1 , num2 );     cout << " The maximum between " << num1 << " and " << num2 << " is " << mini << endl ;     return 0 ; }

46: Write a program to determine the maximum of two number

  // Write a program to determine the maximum of two number #include < iostream > #include < cmath > using namespace std ; int main () {     float num1 , num2 , maxi ;     cout << " Enter first number: " ;     cin >> num1 ;     cout << " Enter second number: " ;     cin >> num2 ;     maxi = max ( num1 , num2 );     cout << " The maximum between " << num1 << " and " << num2 << " is " << maxi << endl ;     return 0 ; }

45: Write a program to check if a character is a vowel or consonant using switch case.

  // Write a program to check if a character is a vowel or consonant using switch case. #include < iostream > using namespace std ; int main (){     char alpha ;     cout << " Enter an alphabet: " ;     cin >> alpha ;     switch ( alpha ){         case ' A ' :             cout << alpha << " is a vowel " << endl ;             break ;         case ' a ' :             cout << alpha << " is a vowel " << endl ;             break ;         case ' E ' :             cout << alpha << " is a vowel " << endl ;             break ;         case ' e ' :             cout...