In this C program, we will learn how to write a program to check if a given number is Odd or Even. In this program, we are displaying the message using printf
function and read the input taken from the user using scanf
function.
Here is the code of the program to check if a given Number is Odd or Even.
/*
C Program to Check if a given Number is Odd or Even
*/
#include <stdio.h>
void main()
{
int num, remainder;
printf("Enter a Number : ");
scanf("%d", &num);
remainder = num % 2;
if (remainder == 0)
printf("%d is an even Number\n", num);
else
printf("%d is an odd Number\n", num);
}
Enter a Number : 5
5 is an odd Number
--------------------------------
Process exited after 2.633 seconds with return value 19
Press any key to continue . . .
Comments