Javatpoint Logo

91-9990449935

 0120-4256464

C if else Statement

The if statement in C language is used to perform operation on the basis of condition. By using if-else statement, you can perform operation either condition is true or false.

There are many ways to use if statement in C language:

  • If statement
  • If-else statement
  • If else-if ladder
  • Nested if

If Statement

The single if statement in C language is used to execute the code if condition is true. The syntax of if statement is given below:

Flowchart of if statement in C

if statement in c

Let's see a simple example of c language if statement.

Output

enter a number:4
4 is even number
enter a number:5

If-else Statement

The if-else statement in C language is used to execute the code if condition is true or false. The syntax of if-else statement is given below:

Flowchart of if-else statement in C

if-else statement in c

Let's see the simple example of even and odd number using if-else statement in C language.

Output

enter a number:4
4 is even number
enter a number:5
5 is odd number

If else-if ladder Statement

The if else-if statement is used to execute one code from multiple conditions. The syntax of if else-if statement is given below:

Flowchart of else-if ladder statement in C

if-else-if ladder statement in c

The example of if-else-if statement in C language is given below.

Output

enter a number:4
number is not equal to 10, 50 or 100
enter a number:50
number is equal to 50
Next TopicC Switch Statement