• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
September 08, 2022 |1.3K Views

Javascript program to find largest of three numbers

Description
Discussion

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

Examples:
Input: A = 200
B = 800
C = 1000
Output: Largest number = 1000

Algorithm to find the largest of three numbers:

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 2 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 the Math. max() method: A Math. max() is a Javascript inbuilt function and it returns the largest number among the provided numbers.