w3resource logo
C Programming Exercises

C Exercises: Check whether a number is even or odd

C Conditional Statement: Exercise-2 with Solution

Write a C program to check whether a given number is even or odd.

Sample Solution:

C Code:

#include <stdio.h>
void main()
{
    int num1, rem1;
 
    printf("Input an integer : ");
    scanf("%d", &num1);
    rem1 = num1 % 2;
    if (rem1 == 0)
        printf("%d is an even integer\n", num1);
    else
        printf("%d is an odd integer\n", num1);
}

Sample Output:

Input an integer : 15                                                                                         
15 is an odd integer 

Flowchart:

Flowchart: Check whether a number is even or odd

C Programming Code Editor:

#include <stdio.h>

void main()
{
    int num1, rem1;
 
    printf("Input an integer : ");
    scanf("%d", &num1);
    rem1 = num1 % 2;
    if (rem1 == 0)
        printf("%d is an even integer\n", num1);
    else
        printf("%d is an odd integer\n", num1);
}

Improve this sample solution and post your code through Disqus.