Solution :
#include<stdio.h>
#include<conio.h>
main()
{
int numb;
printf("Let's Know The Number Is Even Or Odd. \nPlease Enter Your Number : ");
scanf("%d",&numb);
if(numb%2==0)
printf("The
Number Is Even.");
else
printf("The
Number Is Odd.");
getch();
}
Program Analysis :
We know if any number get divided by 2 and the reminder (%) become 0 then the number is EVEN so here I use this logic in this line :
if(numb%2==0)
Here numb is a variable inputted by user and the expression is if the number get divided by 2 and the remainder become 0 than the number is EVEN:
We can also do it like the following :
#include<stdio.h>
#include<conio.h>
main()
{
int numb;
printf("Let's Know The Number Is Even Or Odd. \nPlease Enter Your Number : ");
scanf("%d",&numb);
if(numb%2==1)
printf("The Number Is Odd.");
else
printf("The Number Is Even.");
getch();
}
Program Analysis :
if(numb%2==1)
This expression says that if the given number get divided by 2 then the reminder will be 1 and it will be an odd number otherwise it will be an Even number.
Example Program :
#include<stdio.h>
#include<conio.h>
main()
{
int numb;
printf("Let's Know The Number Is Even Or Odd. \nPlease Enter Your Number : ");
scanf("%d",&numb);
if(numb%2==1)
printf("The
Number Is Odd.");
else
printf("The
Number Is Even.");
if(numb>5)
printf("\nThe
Number Is Grater Than 5");
else
if(numb<5)
printf("\nThe Number Is Less Than 5");
else
if(numb=5)
printf("\nThe Number Is 5");
getch();
}
Hope you get a clear concept on this decision control statement " if "
Post a Comment