Algorithm


  1. Start
  2. Read three numbers (num1, num2, num3) from the user.
  3. Initialize a variable largest to store the largest number.
  4. If num1 is greater than num2 and num1 is greater than num3, set largest to num1.
  5. If num2 is greater than num1 and num2 is greater than num3, set largest to num2.
  6. If num3 is greater than num1 and num3 is greater than num2, set largest to num3.
  7. Display the value of largest as the result.
  8. End

 

Code Examples

#1 Code Example- Largest Number Among Three Numbers

Code - Javascript Programming

// program to find the largest among three numbers

// take input from the user
const num1 = parseFloat(prompt("Enter first number: "));
const num2 = parseFloat(prompt("Enter second number: "));
const num3 = parseFloat(prompt("Enter third number: "));
let largest;

// check the condition
if(num1 >= num2 && num1 >= num3) {
    largest = num1;
}
else if (num2 >= num1 && num2 >= num3) {
    largest = num2;
}
else {
    largest = num3;
}

// display the result
console.log("The largest number is " + largest);
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter first number: -7
Enter second number: -5
Enter third number: -1
The largest number is -1

#2 Code Example- Using Math.max()

Code - Javascript Programming

// program to find the largest among three numbers

// take input from the user
const num1 = parseFloat(prompt("Enter first number: "));
const num2 = parseFloat(prompt("Enter second number: "));
const num3 = parseFloat(prompt("Enter third number: "));

const largest = Math.max(num1, num2, num3);

// display the result
console.log("The largest number is " + largest);
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter first number: 5
Enter second number: 5.5
Enter third number: 5.6
The largest number is 5.6
Advertisements

Demonstration


JavaScript Programing Example to Find the Largest Among Three Numbers-DevsEnv

Previous
JavaScript Practice Example #3 - Assign 3 Variables and Print Good Way