Posts

Showing posts with the label continue-break

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