You will be using the if...else if...else statement to write the program.
Example 1: Check Number Type with if...else if...else
Output
Enter a number: 0 The number is zero.
The above program checks if the number entered by the user is positive, negative or zero.
- The condition
number > 0checks if the number is positive. - The condition
number == 0checks if the number is zero. - The condition
number < 0checks if the number is negative.
The above program can also be written using the nested if...else statement.
Example 2: Check Number Type with nested if...else
Output
Enter a number: 0 You entered number zero
The above program works the same as Example 1. However, the second example uses the nested if...else statement.