This program is to check whether the number provided by the user is even or odd. As you aware that even numbers are completely divisible by zero i;e they leave remainder zero when divided by two. On the other hand, odd numbers are not completely divisible by two. So, we can make use of the remainder operator(%) in c to check whether a number is odd or even.

/* Program to check whether the number is even or odd using the modulus operator (%) */ #include<stdio.h> int main() { int n; printf("Enter an integer: "); scanf("%d",&n); // Modulus (%) returns remainder if ( n%2 == 0 ) // returns true if remainder is 0 printf("%d is an even number", n); else printf("%d is an odd number", n); return 0; }

Case 1: Enter an integer: 6723 6723 is an odd number Case 2: Enter an integer: 4578 4578 is an even number

Modulus operator in C programming language, denoted by %, returns the remainder after the division operation. Here we have perform the modulus operator on the number provided by the user and checked whether it is equal to zero(n%2 == 0). The if statement is executed automatically if the expression inside it returns true value. Otherwise, the else statement is executed.

Questions from Previous year GATE question papers

UGC NET Previous year questions and practice sets

Attempt a small test to analyze your preparation level. This GATE exam includes questions from previous year GATE papers.

Practice test for UGC NET Computer Science Paper. The questions asked in this NET practice paper are from various previous year papers.