This is a C program to check whether a given integer is odd or even.
The program takes the given integer and checks whether the integer is odd or even.
1. Take the integer to be checked as input.
2. Find the remainder of the integer by dividing it by 2.
3. Use if,else statement to check whether the remainder is equal to zero or not.
4. Print the output and exit.
Here is source code of the C program to check whether a given integer is odd or even.The C program is successfully compiled and run on a Linux system. The program output is also shown below.
#include <stdio.h>
void main()
{
int ival, remainder;
printf("Enter an integer : ");
scanf("%d", &ival);
remainder = ival % 2;
if (remainder == 0)
printf("%d is an even integer\n", ival);
else
printf("%d is an odd integer\n", ival);
}
1. User must first enter the integer to be checked which is stored in the variable ival.
2. Find the remainder of the integer by dividing the variable ival by integer 2 and the value is stored in the variable remainder.
3. Use if,else statement to check whether the value of the variable remainder is equal to zero or not.
4. If it is equal to zero, then print the output as “the integer is an even integer”.
5. If it is not equal to zero, then print the output as “the integer is an odd integer”.
Case 1: Enter an integer : 24 24 is an even integer Case 2: Enter an integer : 75 75 is an odd integer Case 3: Enter an integer : 0 0 is an even integer
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms