C Program to find the largest of three numbers

The following is a C program to find the largest of the three numbers:

Expected Output:

1st run:

2nd run:

How it works

The program starts off by asking the user to enter three digits (a, b and c).

In line 20, we check whether a is greater than b. If the condition a > b evaluates to true (1) the program control comes to the nested if statement in line 22 and checks whether a > c. If the condition a > c evaluates to true (1), then a is the largest number. Otherwise, c is the largest number.

If the condition in line 20, evaluates to false, then we can say for sure that b > a.

In line 33, we check whether b > c. If it is, then b is largest number. if the condition fails, then we can conclude that c > b.

Since, b > a and c > b. Therefore, c > b > a. Hence, c is the largest number.


Recommended Reading:

Leave a Comment

%d bloggers like this: