Program to find the greatest of three numbers using nested if-else statement in C/C++

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code
  4. Download Code

Code


To copy code: Click  View Source “View Source” on the right of this code snippet.


Background and Explanation of the code


1.In the above program , the user is prompted to enter the values of three numbers a, b, c.

2.It first checks the test condition (a>b). If this condition is true then it checks for a test condition (a>c) using if-else block contained in it.

3. If the condition (a>c) is true then message A is greatest is displyed otherwise message C is greatest is displayed .

4. But if the condition (a>b) is false then it checks for test condition (b>c) using another if-else statement contained in within else block.

5.If the condition (b>c) is true then message B is greatest is displayed otherwise message C is greatest is displayed.

On execution of the program the output is shown:

Enter three numbers(A,B,C)
3(Press Enter)
2(Press Enter)
5(Press Enter)
C= 5 is greatest