• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 06, 2022 |1.6K Views
C Program to Find the Largest among three Numbers
  Share  2 Likes
Description
Discussion

In this video, we will write a C program to find the largest of the three numbers.

Examples:
Input: A = 150
B = 250
C = 100
Output: Largest number = 250

Algorithm:

Step 1: Start
Step 2: Read the three numbers to be compared, X, Y, and Z.
Step 3: Check if X is greater than Y
a. If true, then check if X is greater than Z.
    (i)  If true, print 'X' as the greatest number.
    (ii) If false, print 'Z' as the greatest number.
b. If false, then check if Y is greater than Z.
     (i) If true, print 'Y' as the greatest number.
     (ii) If false, print 'Z' as the greatest number.
Step 4. End

In this video we see three different approaches for finding the largest number among three numbers:

1. Using an if-else statement: In this method, we use the if-else statement with && operators to find the largest numbers in given numbers.
2. Using ternary operators: In the second method, we use ternary operators. 
A ternary operator has the following syntax:
exp1? exp2: exp3
Where expression 1 will be evaluated always. Execution of expression 2 and expression 3 depends on the outcome of expression1. If the outcome of expression 1 is non zero expression 2 will be evaluated, otherwise, expression 3 will be evaluated.

3. Using the fmax() method: A fmax() is an inbuilt function and it returns the largest number among the provided numbers.

C program to Find the Largest Number Among Three Numbers
https://www.geeksforgeeks.org/c-program-to-find-the-largest-number-among-three-numbers/

Read More