C Program to find Odd or Even number

This program I am writing for school students and for fresher programmers who wish to learn C language by themselves.

To find if an entered number is Odd or Even, you need to know the basic mathematics. Any number which is divided exactly by 2 is an Even number.

For example 12 / 2 = 6 (quotient), and the remainder is 0 (zero); So basically if the remainder value is Zero (0) it is an Even number

In C you have two operators to get the quotient (/) and the remainder value (%). So in our case we have to use the modulus operator (%) to figure out whether the entered number is an Odd number or an Even number.

Let’s write the C program to Find Odd or Even Number:

#include <stdio.h>
#include <string.h>
int main()
{
	int num;
		
	//print about the program
	printf("C Program to find Odd or Even number\n");
    printf("Enter a Number: ");
   	
	//get the input number from the user
	scanf("%d", &num);
	
	//use % modulus to figure out whether the 
	//entered number is odd or even.
	if(num % 2 == 0){
		printf("It is an Even number");
	}else{
		printf("It is an Odd number");
	}
    return 0;
}

Output of the above program will be:

C Program to find Odd or Even number
Enter a Number: 12
It is an Even number

 

Leave a Comment

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

Scroll to Top