C++ if-then-else
Introduction
if statement is used to execute a block of code only when a condition is true.
If the condition is false, the block of code will not be executed. The syntax of if statement is:
Code - if statement
Example:
int x = 10;
if (x > 5) {
cout << "x is greater than 5";
}
Code - if-else statement
Example:
int x = 10;
if (x > 5) {
cout << "x is greater than 5";
} else {
cout << "x is less than or equal to 5";
}
Task
Write a program that takes an integer as input and prints whether the number is even or odd.
Input
An integer n (1 <= n <= 1000).
Output
"n is even" if n is even
"n is odd" otherwise.
"Invalid input" if n is not in the range.