C++ if-else

In C++ programming, if statement is used to test the condition. There are various types of if statements in C++.

  • if statement
  • if-else statement
  • nested if statement
  • if-else-if ladder

C++ IF Statement

The C++ if statement tests the condition. It is executed if condition is true.

Cpp If else 1

C++ If Example

Output:/p>

It is even number

C++ IF-else Statement

The C++ if-else statement also tests the condition. It executes if block if condition is true otherwise else block is executed.

Cpp If else 2

C++ If-else Example

Output:

It is odd number

C++ If-else Example: with input from user

Output:

Enter a number:11
It is odd number

Output:

Enter a number:12
It is even number

C++ IF-else-if ladder Statement

The C++ if-else-if ladder statement executes one condition from multiple statements.

Cpp If else 3

C++ If else-if Example

Output:

Enter a number to check grade:66
C Grade

Output:

Enter a number to check grade:-2
wrong number

Next TopicC++ switch




Latest Courses