# C Program to Check Whether a Given Number is Even or Odd

«
»

This is a C program to check whether a given integer is odd or even.

Problem Description

The program takes the given integer and checks whether the integer is odd or even.

Problem Solution

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.

Program/Source Code

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.

1. `#include <stdio.h>`
2. ` `
3. `void main()`
4. `{`
5. `    int ival, remainder;`
6. ` `
7. `    printf("Enter an integer : ");`
8. `    scanf("%d", &ival);`
9. `    remainder = ival % 2;`
10. `    if (remainder == 0)`
11. `        printf("%d is an even integer\n", ival);`
12. `    else`
13. `        printf("%d is an odd integer\n", ival);`
14. `}`
Program Explanation

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”.

Runtime Test Cases
```
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 Books in C Programming, Data-Structures and Algorithms 