In this tutorial you will learn about the C++ Programs to Check Even and Odd Number and its application with practical example.
C++ Program to Check Even and Odd Number
In this tutorial, we will learn to create a C++ program that will Check Even and Odd numbers using C++ programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Operators in C++ Programming.
- Basic Input and Output function in C++ Programming.
- Basic C++ programming.
- Conditional Statements in C++ programming.
- Arithmetic operations in C++ Programming.
What is an even and odd number?
Even numbers are those numbers that are completely divisible by 2. which means the reminder should be zero. And odd numbers are those numbers that cannot be completely divisible by 2.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the input integer number from the user. 3. Checking the Even & Odd numbers from the input. 4. Printing the result number. 5. End Program. |
Program to Check Even and Odd Number
In this program, we will take an integer input number from the user, and then we will use it in the program with conditional statements to find whether the number is even or odd. As per the program calculations.
With the help of this program, we can Check Even and Odd numbers.
Program:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* C++ Programs to Check Even and Odd Number */ #include <iostream> using namespace std; int main() { /* Declaring the variable for the program to check even and odd number */ int n; /* Taking the input number from the user */ cout << "Enter an integer: "; cin >> n; /* Checking the number even or odd */ if ( n % 2 == 0) /* Printing the even number in the output */ cout << n << " is even."; else /* Printing the odd number in the output */ cout << n << " is odd."; return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- n = it will hold the integer value.
Input number from the user.
Checking if even number.
Checking for an odd number.