If Else program in C++

Write a program to find the even and odd number?

Download Code (Dev C++)

Logic:

Number is even if number%2=0 

For example: 4%2=0 so 4 is even, 8%2=0 SO 8 is even

Number is odd if number%2 !=0

For example: 7%2 != 0 so 7 is odd, 13%2 != 0 SO 13 is odd.

Program:

program to find the odd even number
Output:
program to find the even odd number
Explanation:

Statement 1: Adding the header file iostream

Statement 2: Adding the namespace

Statement 3: Starting of integer type main function

Statement 4:

Starting of main function

Statement 5: Declaration of integer type variable named as no. Variable no can have any value.

Statement 6: Display message.

Statement 7: User input the integer value and value is stored in variable no.

Statement 8: Value in variable no is checked by if condition. If value of no is divided by 2 and remainder is 0, then the number is even and control moves to the statement 9.But if value of no is divided by 2 and remainder is not 0, then the number is odd and control moves to the statement 12.

Statement 9: start of if.

Statement 10: Display the message that number is even.

Statement 11: end of if.

Statement 12: Control arrives at statement 12 if the condition is false at statement 8. 

Statement 13: Start of else.

Statement 14: Display message that number is odd.

Statement 15: End of else.

Statement 16: End of main function.