Algorithm
1. Start
2. Declare an integer variable 'number'
3. Read input into 'number' from the user
4. If (number % 2 == 0)
4.1 Display "Number is even"
Else
4.2 Display "Number is odd"
5. End
Code Examples
#1 Code Example- C++ Programing Check Whether Number is Even or Odd using if else
Code -
C++ Programming
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter an integer: ";
cin >> n;
if ( n % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";
return 0;
}
Copy The Code &
Try With Live Editor
Output
Enter an integer: 23
23 is odd.
23 is odd.
#2 Code Example- C++ Programing Check Whether Number is Even or Odd using ternary operators
Code -
C++ Programming
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter an integer: ";
cin >> n;
(n % 2 == 0) ? cout << n << " is even." : cout << n << " is odd.";
return 0;
}
Copy The Code &
Try With Live Editor
Output
Enter an integer: 23
23 is odd.
23 is odd.
Demonstration
C++ Programing Example to Check Whether Number is Even or Odd-DevsEnv