C Program to Check if a given Integer is Odd or Even

C Programming Computer Science

Below is code in C language to check whether the number to be checked is even or odd.

Source Code:

This source code can be used to check whether the input number is even or odd. This is the simplest c program to perform the given even odd task.

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

 

Dry Run:

Case 1:
Enter an integer : 34
34 is an even integer
 
Case 2:
Enter an integer : 25
25 is an odd integer
 
Case 3:
Enter an integer : 0
0 is an even integer

 

Similarly, you can check any integer whether it is even or odd.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.