C Program to determine whether given number is even or odd

      To find whether a given number is even or odd, the given below program divides the given number by 2. If finds remainder using modulus operator. If this remainder is zero then given number is even otherwise the given number is odd.

This is the simple math that we learn during our schooling and it is the same logic that we make use here in order to find whether a given number is even or odd.

even or odd program in c

Source Code:

 int main()
	int n,r;
	printf("\nEnter the number:");
	scanf("%d", &n);          //Step 1
	r=n%2;                    //Step 2
	if(r==0)                  //Step 3
		printf("EVEN");       //Step 4
	return 0;


Sample Test cases:

1. nter the number: 5
2. Enter the number: 4
3. Enter the number: 11


Step 1: Program reads a number from the user using scanf() function.

Step 2: The remainder of a given number when divided by 2 is found using modulus operator and is stored in variable ‘r’.

Step 3: Using If condition the variable ‘r’ is checked whether it has zero or non-zero value

Step 4: If r==0 then given number is EVEN otherwise ODD.

Explore C Programs: C Programs
More Content : C Programming