Even Odd Program in C

Spread the love

In this article, you will learn whether the user has entered an even or odd number by using the even-odd program in c.

If the number which is perfectly divisible by “2” then those numbers are even numbers(2, 4, 6, 8).

If any number that is not perfectly divisible by “2” then those numbers are called as odd numbers(1, 3, 5, 7, 9).

Here you can learn how to write even odd program in c using for loop, while loop, do-while loop, if-else, function, ternary operator and many other ways.

Even Odd Program in C
Even Odd Program in C

Even odd program in C using if else in C:

#include <stdio.h>
int main() {
int a=9;
if(a % 2==0)
{
printf("%d is an even number",a);
}
else
{
printf("%d is an odd number", a);
}    
return 0;
}

If you want to know more about how if else works then check If else in C with examples

Values entered by the user:

#include<stdio.h>
int main()
{
int a;
printf("Enter a value to check an even or odd number");
scanf("%d",&a);
if(a%2==0)
{
printf("%d is an even number",a);
}
else
{
printf("%d is an odd number",a);
}
return 0;
}

Even odd program in c using the ternary operator:

#include<stdio.h>
int main()
{
int a;
printf("Enter a value: ");
scanf("%d", &a);
(a%2==0)? printf("%d is an even number", a) : printf("%d is an odd number", a);
return 0;
}

Even odd program in C using bit wise operator:

#include<stdio.h>
int main()
{
int a;
printf("Enter a value: ");
scanf("%d",&a);
if(a & 1)
{
printf("%d is an odd number",a);
}
else
{
printf("%d is an even number", a);
}
return 0;
}

in C

Even Odd Program in C
Even Odd Program in C

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top