Posts

Showing posts from May, 2017

Switch Statement Programs

Switch Statement Programs: Program 1: #include < iostream > using namespace std; int main() { char num; cin >> num; switch ( num ) { case 'A': cout << "Adventure Movie" << endl; break; case 'C': cout << "Comedy Movie" << endl; break; case 'F': cout << "Family Movie" << endl; break; case 'H': cout << "Horror Movie" << endl; break; case 'S': cout << "Science Fiction Movie" << endl; break; default: cout << "invalid command" << endl; } return 0; }

Switch Statement-Syntax - C++ Programming

Switch Statement: Syntax: switch(expression) { case (condition): ___statement___ break; case (condition): ___statement___ break; default: ___statement___ }

Program to input 5 numbers and to display its positive and negative divisers of both even and odd numbers respectively:

Program to input 5 numbers and to display its positive and negative divisers of both even and odd numbers respectively: Program: #include < iostream > using namespace std; int main() { int num; for(int i = 0 ; i < 5 ; i++) { cout << "Enter the number please" << endl; cin >> num; if(num % 2 == 0) { if(num >= 0) { cout << "Possitive even number" << endl; } else { cout << "Negative even number" << endl; } else { if(num >= 0) { cout << "Possitive odd number" << endl; } else { cout << "Negative odd number" << endl; } } return 0; }

How to find Even and Odd numbers - C++ Programming

To find Even and Odd: To find that whether the entered number is even or odd we uses the following programs Program: #include < iostream > using namespace std; int main() { int num; cout << "Enter the number please" << endl; cin >> num; if (num % 2 == 0) { cout << "number is even" << endl; } else { cout << "Number is odd" << endl; } return 0; } Program: #include < iostream > using namespace std; int main() { int num; cout << "Enter the number please" << endl; cin >> num; if (num % 2 != 0) { cout << "number is odd" << endl; } else { cout << "Number is even" << endl; } return 0; }

Modulus Operator

Modulus Operator: Modulus operator is used to take out the remainder. Program: #include < iostream > using namespace std; int main() { int num; cout << "Enter the number please" << endl; cin >> num; if (num % 2 == 0) { cout << "number is even" << endl; } else { cout << "Number is odd" << endl; } return 0; }

Not Operator

Not Operator: Program: #include < iostream > using namespace std; int main() { int num; cout << "Enter the number please" << endl; cin >> num; if (num != 0) { cout << "Number is not zero" << endl; } else { cout << "Number is zero" << endl; } return 0; }

Or Operator

Or Operator Or operator is used when we want that if any one of the given condition in the program is true then it shows the output. Program: #include < iostream > using namespace std; int main() { int num; cout << "Enter the number please" << endl; cin >> num; if (num == 1 || num > 0) { cout << "Entered number is a positive number" << endl; } else { cout << "Type the number again" << endl; } return 0; }

And Operator

And Operator: And operator is used when we want that if both conditions given in the program are true then it shows the output. Program: #include < iostream > using namespace std; int main() { int num; cout << "Enter the number please" << endl; cin >> num; if (num == 1 && num > 0) { cout << "Entered number is a positive number" << endl; } else { cout << "Entered number is a negative number" << endl; } return 0; }