In this post ,I will tell you how to make a C program which can check a Integer entered by the user is Even OR Odd . So, without any further delay let's get started.
Code:
#include <stdio.h>
int main()
{
int Integer;
printf("Enter any Integer to check for Even or Odd \n");
scanf("%d", &Integer);
if (Integer % 2 == 0)
{
printf("It is a Even number\n");
}
else
{
printf("It is a Odd number\n");
}
return 0;
}
First let us understand what is even number and what is odd number. Even number is any number that completely divisible by 2 means leaves remainder zero. And odd number is one which does not completely divides itself by 2 means leaves something in remainder. Now let us see code of this and understand it in language of coder. Now you have understand what is even and what is odd number .It time to understand above code .For this we first declare variable name Integer of type int. To store integer values then we print statement "Enter any integer to check Even or odd" using printf() .And store value entered by user in Integer variable . And now we use if(Integer%2==0) means if remainder by dividing Integer is 2 comes out to be zero .Then it is a Even number and using printf( ) function we print ."It is Even Number" .If this condition is false that means it is odd number .And we print it .
No comments:
Post a Comment