w3resource

C Exercises: Check whether a number is even or odd


2. Even or Odd Check

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

Visual Presentation:

Check whether a number is even or odd


Sample Solution:

C Code:

#include <stdio.h>   // Include the standard input/output header file.

void main()
{
    int num1, rem1;   // Declare two integer variables 'num1' and 'rem1'.

    printf("Input an integer : ");   // Prompt the user to input an integer.
    scanf("%d", &num1);   // Read and store the user's input in 'num1'.
    rem1 = num1 % 2;   // Calculate the remainder of 'num1' when divided by 2.
    if (rem1 == 0)   // Check if the remainder is equal to 0.
        printf("%d is an even integer\n", num1);   // Print a message indicating that 'num1' is an even integer.
    else
        printf("%d is an odd integer\n", num1);    // Print a message indicating that 'num1' is an odd integer.
}

Output:

Input an integer : 15                                                                                         
15 is an odd integer 

Flowchart:

Flowchart: Check whether a number is even or odd


For more Practice: Solve these Related Problems:

  • Write a C program to determine if a number is even or odd using only bitwise operators.
  • Write a C program to check the even/odd status for a sequence of numbers provided on one input line.
  • Write a C program to determine if the sum of two integers is even or odd.
  • Write a C program to check if a number is even without using the modulus operator.

Go to:


PREV : Equality Check.
NEXT : Positive or Negative Check.

C Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.