# Check whether a number is an Even or Odd program in C

## Description:

Check whether the given number is an Even or Odd Program in C using the if else statement.

The Program will request the user to enter a positive number, Based on the user input number program will display the result, whether the given number is an Even number or an Odd Number.

### Pre-Requisites:

You need to know the basics of decision-making statements like if else statement. Please read the following article.

## Program Explanation or Algorithm:

• The program will start by asking the user for a Positive Number.
• Once the user enters a Number, we store it in number variable.
• Then we are checking if the given number is an Even Number of Odd number using the modulus operator
• The number % 2 == 0 , Means We are modulo dividing the number with the 2. If the result of number % 2 is zero, Then the number is an Even Number ( As it is perfectly divisible by the 2). So we will print the message saying Given Number is Even Number
• If the number % 2 is not equal to zero, Then it is equivalent to 1, Which means the number is Odd Number, So we will print the Odd Number message on the console.

## Even or Odd Program in C with Positive number check:

Letâ€™s re-write the above program by adding an extra check to show the error message if the user enters a Negative number.

We are going to use the goto statement to take control back the user input statement (printf/scanf)

### Program Output:

As you can see from the above output, We are only allowing positive numbers. If the user enters the Negative Number, Then we are displaying the error message ERROR: Negative number provided. Enter Positive Number and took the program control back to the printf statement, so that the user can enter the number again.

Here we used the goto statement to jump from one statement in the program to another statement.

### More C Programs:

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

### 3 Responses

1. [â€¦] Check given number is positive or negative number or Zero [â€¦]

2. [â€¦] earlier programs, we discussed the Even or Odd number program using the if else statement. In todayâ€™s article, We are going to write a C program to check Even or Odd number using [â€¦]

3. [â€¦] C Program to check whether a number is Even or Odd [â€¦]