Program in C++ to check that whether a number is even or odd with flowchart
Program in C++ to check whether a number is even or odd with the flowchart
In this tutorial, we will learn about the followings;
- Flowchart of even-odd number program.
- Program in C++ to check whether a number is even or odd?
- Program in C to check whether a number is even or odd?
Algorithm of the program to check whether a number is even or odd
Step 1: Start
Step 2: Take Input and Read the Numbers
Step 3: Check that If Number % 2 == 0
If true ThenPrint : Your selected Number is an Even Number.
Else
Print : Your selected Number is an Odd Number.
Step 4: Finish
Flowchart of even-odd number program
Program in C++ to check whether a number is even or odd?
We can write and test the program by randomly take two values. one value that can false the condition and another one that can result in True.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<iostream> using namespace std; int main() { int number; cout<<"Enter The Number You Want To Check?"; cin>>number; if(number%2==0) { cout<<"Hi, Number is Even"; } else { cout<<"Hi, Number is ODD"; } } |
Output
C++ Program to check even odd number using switch case statement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> using namespace std; int main(){ int Number; cout<<"Enter any Number to check even or odd number: "; cin>>Number; switch(Number % 2) { case 0: cout<<"The Number is even number."; break; case 1: cout<<"The Number is odd number."; break; } return 0; } |
C++ Even odd program using user define functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <iostream> using namespace std; bool T4Tutorials(int number); int main(){ int number; bool isEven; cout<<"Enter any number: "; //Storing the entered value in variable number cin>>number; //Calling the function that checks even odd isEven = T4Tutorials(number); if(isEven) cout<<number<<" The number is an even number"; else cout<<number<<" The number is an odd number"; return 0; } bool T4Tutorials(int number){ bool b; /* If number is perfectly divisible by 2 then it is * an even number else it is an odd number * */ if (number % 2 == 0) b=true; else b=false; return b; } |
C++ Even Odd program starting from a number and till ending number using for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> using namespace std; int main() { //declare variables int Digit; int n; cout << "Enter value less than 50: "; cin >> n; //take user input // print odd values cout << "The odd Digits are:"; for (Digit = n + 1 - (n % 2); Digit <= 50; Digit += 2) { cout << " " << Digit; } cout << endl; // print even values cout << "The even Digits are:"; for (Digit = n + (n % 2); Digit <= 50; Digit += 2) { cout << " " << Digit; } cout << endl; return 0; //end of program } |
Output
Enter value less than 50: 9
The odd Digits are: 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 4
9
The even Digits are: 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48
50
Program in C to check whether a number is even or odd?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include<stdio.h> #include<conio.h> void main() { int number; printf("Please Enter The Number You Want To check?"); scanf("%d",&number); if(number % 2 == 0) { printf("Hi, Number Is Even"); } else { printf("Hi, Number Is ODD"); } getch(); } |
Output
Even odd number Program in C using switch statement?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <stdio.h> int main() { int Number; /* Input a Number from user */ printf("Enter any Number to check even or odd number.: "); scanf("%d", &Number); switch(Number % 2) { /* If n%2 == 0 */ case 0: printf("The Number is Even number."); break; /* Else if n%2 == 1 */ case 1: printf("The Number is Odd number."); break; } return 0; } |
C Program to check even odd number using for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include<stdio.h> #include<conio.h> int main() { int n; int EndingNumber; printf("\n Enter EndingNumber: "); scanf("%d",&EndingNumber); printf("\n Even Number List :\n "); n=2; while(n<=EndingNumber) { printf(" %d",n); n=n+2; } printf("\n\n Odd Number List :\n "); n=1; while(n<=EndingNumber) { printf(" %d",n); n=n+2; } getch(); } |
C++ Exercise | If else Statement
- calculate the bill
- character is small, capital or a special character
- a number is even or odd
- 0 is a positive or negative number
- a positive and negative number
- Enter Range of numbers and replaced them
- a greater number among three numbers
- Armstrong Number
- ASCII codeÂ
- Find the Maximum value program in C++ (C Plus Plus).
- maximum number
- Maximum Number between two numbersÂ
- Student Grade
- the number is divisible by 11 or 5 or not
- TriangleÂ
- a triangle is an equilateral, isosceles or scalene
- Leap yearÂ
- character is an alphabet or not
- Grade Percentage
- character is an alphabet, digit, or special character
- character is an uppercase or lowercase.
- Weekdays
- a prime or composite number
- hours and minutes as AM or PM
- swap the values of two numbers
- update even to odd
- Profit Loss
- centimeter into meter and kilometerÂ
- TriangleÂ
- Salary
- Even odd with goto statement.
- area of the circle