C Language = Check whether the number is even or odd
Check whether the number is even or odd
#include<stdio.h>
void main()
{
int a;
char ch[10];
printf("enter a number\n");
scanf("%d",&a);
if (a>0)
{
printf("it is positive %d\n",a);
if (a%2==0) // we can use a%2 because 0 is false and 1 is true for eg see part 3
{
printf("it is even %d",a);
}
else
{
printf("it is odd %d",a);
}
}
if (a<0)
{
printf("it is negative %d",a);
}
}
Comments
Post a Comment