Example(s):Palindrome, prime, armstrong, "linear search", reverse etc.
Example(s):1575, 1632, 1539 (Only one at a time)
Login
[lwa]
Solved Problem
#CPP#2012
Problem Statement - Even odd test
Write a c++ program to test if the user given integer value is an even number or an odd number.
Solution
TC++ #2012
Run Output
Enter an integer :23
The number is odd
-OR-
Enter an integer :22
The number is even
if(n%2==0) cout<<“The number is even”;
If the remainder of number when divided by 2 is 0 then it is an even number. This is called divisibility test, which is done by using the % (Mod) operator.
else cout<<“The number is odd”;
This is printed when the if condition is not true. So if the divisibility by 2 is not true then it is an odd number.