w3resource logo


C Programming Exercises

C Exercises: Check whether a number is even or odd

Secondary Nav

C Conditional Statement: Exercise-2 with Solution

Write a C program to check whether a given number is even or odd.
Test Data :
15 
Expected Output
:
15 is an odd integer 

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);
}

Flowchart :

Flowchart: Check whether a number is even or odd

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.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number