Breaking

Tuesday, February 19, 2019

#5: C Program to Find the Integer For Even Or Odd

  To Check the integer is Even or Odd

C Program to Check Odd or Even using IF Condition

This C program allows the user to enter integer and checks whether that number is even or odd using If statement.
Source Code:
/* C Program to Check Odd or Even using IF Condition */

#include<stdio.h>

int main()
{
  int number;

  printf(" Enter an int value to check Even or Odd \n");
  scanf("%d", &number);
  
  if ( number%2 == 0 ) //Check whether remainder is 0 or not
     printf("Given number %d is EVEN NUMBER \n", number);

  else
    printf("Given number %d is ODD NUMBER \n", number);

  return 0;
}
Output Console:


AnalysisBelow printf statement will ask the user to Enter an integer value to check whether it is Even or Odd.

printf(" Enter an int value to check Even or Odd \n ");
Below scanf statement will assign the user entered a value to number variable.
scanf(" %d ",&number);
In the Next line, We declared the If statement
if ( number % 2 == 0 )
Any number that is completely divisible 2 is even number. If condition will check whether the remainder of the number divided by 2 is exactly equal to 0 or not.
  • If the condition is True then it is Even number
  • If the condition is False then it is Odd number

No comments:

Post a Comment

Popular Posts

Post Top Ad

Your Ad Spot

Pages