In this program, you will know how to find even and odd numbers in c++. Even numbers are those numbers that can divide on 2 and odd numbers are those that can not be divided on 2.
For this article you should have the knowledge of following topics of C++ Programming.
Example 1: Check Even and Odd number enter by user in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include<iostream> using namespace std; int main() { int number; cout<<"Enter any Number : "; cin>>number; if(number%2==0) cout<<"You entered an even number : "<<number; else cout<<"You entered an odd number : "<<number; return 0; } |
Example 2: Find Even Numbers in Given Range
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include<iostream> using namespace std; int main() { int num; for(num=1;num<=10;num++) { if(num%2==0) cout << num<<"\t"; } return 0; } |
Example: Find Odd Numbers in Given Range
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include<iostream> using namespace std; int main() { int num; for(num=1;num<=10;num++) { if(num%2!=0) cout << num<<"\t"; } return 0; } |