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.

Video Lecture

By: Prof. Fazal Rehman Shamil    CEO @ T4Tutorials
Whatsapp: +92 302 87 000 85     Facebook: For Discussions

11 thoughts on “If Else program in C++

  • June 17, 2019 at 5:51 pm
    Permalink

    Thank you for creating such a great environment to learn and where we were encouraged to express our own thoughts and opinions.

  • April 16, 2019 at 2:34 pm
    Permalink

    I have never seen such a nice website. In this program, we able to find an even or odd number..in this program, first of all, we declare variable no.and apply IF and ELSE condition…If no%2==0 then no is even
    ELSE no is odd.
    thanks, sir

  • April 15, 2019 at 7:23 pm
    Permalink

    this brilliant way of teaching made me motivated me about programming. specially briefing the logic behind the program and then use of code.
    according to condition through if & else statement that whether it is even or odd.if reminder is equal to zero is displayed even either it displays odd

  • April 15, 2019 at 6:51 pm
    Permalink

    The explanation made easier for me to understand which statement is for what.
    Conventionally, the variable is declared and value is taken from the user using predefined functions, but it’s more amazing to see how the condition in if statement is used just once rather than using another variable for that, then storing its remainder and using it again in if statement.

  • April 13, 2019 at 4:27 am
    Permalink

    Well..!!!
    An integer is divisible by 2 and there is no reminder then number r is called Even number
    this program is founding about a number is whether even or odd
    A logic (of if and else statement) is used that if the given input when divided by two and the remainder is zero the number is even and if the remainder is not zero the number is odd
    first, enter the input and then use the logic that if the number, divided by 2 is equal to zero (reminder) the number is even otherwise if the remainder is not zero then the number is negative
    For Example
    If(num/2==0)
    even
    else
    odd

  • April 12, 2019 at 5:25 pm
    Permalink

    Sir, i get the understanding that first, we have to declare the variable of a number than take the number using if else statement.if the value of number divide by 2 and remainder is 0, then the number is even.if the number is divided by 2 and the remainder is not zero, then the number is odd.

  • April 12, 2019 at 4:29 pm
    Permalink

    Thanks. Confusion is solved that we have to take the number from the user than uses if-else condition to check the number is odd or even. If the remainder is zero by dividing the number by 2 than it is even number.If the remainder is not equal to zero by dividing the number by 2 than it is an odd number.

  • April 12, 2019 at 2:34 pm
    Permalink

    Nice to see this post. I think in this program first, we have to declare the variable of a number than take the number from the user than using if & else conditions if the number is divided by 2 become 0 than cout that the number is even if the number doesn’t become 0 cout that the number is odd

  • April 12, 2019 at 2:17 pm
    Permalink

    The author is explaining in a good way that We made this programme to identify rather the given number is odd or even.
    For that we stored a number in a variable after that we made a condition if the remainder of given number comes zero when dividing it with 2 then it will be an even number else it will be an odd number.

  • April 12, 2019 at 11:20 am
    Permalink

    This program is used to find that the number is even or odd. I observe that the author declare a variable (no) And display a message (enter any number). if the number is divisible by 2 it prints even number, else it the print number is even.

  • April 12, 2019 at 10:44 am
    Permalink

    According to the given program, we find no.is even or odd, So We declare A variable called no. Enter no.from the user. If no.is divide by 2 the remainder is Zero.
    Print Even num. If No. divides 2 the reminder should not equal to zero. Print Odd num.

Leave a Reply

Your email address will not be published. Required fields are marked *