13

C Program to Find the Largest among three Numbers

 3 years ago
source link: https://www.geeksforgeeks.org/videos/c-program-to-find-the-largest-among-three-numbers/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
C Program to Find the Largest among three Numbers
Hey guys. Welcome to Geeks for geeks today we will
  • 100 Views
  • 06/09/2022

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/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK