check wheather a no. is even or odd in c programming
Even or odd using the if else condition
#include<stdio.h>int main()
{
int n;
printf("Enter no. which is to be checked :\n");
scanf("%d",&n);
if(n%2==0)
{
printf("given number %d is Even no.",n);
}
else
{
printf("given number %d is Odd no." ,n);
}
return 0;
}
Even or odd usinng bit wise operator
#include<stdio.h>
int main()
{
int n;
printf("Enter a number which is to be check :\n");
scanf("%d",&n);
if(n&1==0)
{
printf("given no. is odd");
}
else
{
printf("given no. is even");
}
return 0;
}
Even or odd using division method
#include<stdio.h>
int main()
{
int n;
printf("Enter a no.");
scanf("%d",&n);
if((n/2)*2==n)
{
printf("given no. is even no.");
}
else
{
printf("given no. is odd no.");
}
return 0;
}

No comments:
Post a Comment