Skip to main content

Write an Algorithm to find largest of 3 numbers

Description

This algorithm aims to find the largest number among three input numbers. It begins by declaring four containers (variables) to hold values: n1, n2, n3, and MAX. The user is prompted to input three numbers, which are stored in n1, n2, and n3. The algorithm then compares these numbers to determine the largest one, storing it in the MAX variable. Finally, it displays the largest number (MAX) to the user.

Algorithm
Step 1 → START
Step 2 → Declare four variables n1, n2, n3 and MAX.
Step 3 → Read (input) three numbers and store in n1, n2 & n3 respectively
Step 4 → Let MAX = n1
Step 5 → if (n2 > MAX) , then MAX = n2, else next step
Step 6 → if (n3 > MAX), then MAX = n3, else next step
Step 7 → Display (output) MAX as Largest Number.
Step 8 → STOP

What does this mean ?

  • Step 1: START. This marks the beginning of the algorithm.
  • Step 2: Declare four variables n1, n2, n3, and MAX. These are containers to hold values.
  • Step 3: Read (input) three numbers and store in n1, n2, and n3 respectively. Get numbers from the user and store them in n1, n2, and n3.
  • Step 4: Let MAX = n1. Initialize MAX with the value of n1.
  • Step 5: Check if n2 is larger than MAX. If yes, update MAX to be n2.
  • Step 6: Check if n3 is larger than MAX. If yes, update MAX to be n3.
  • Step 7: Display (output) MAX as the Largest Number. Show the largest number (MAX) to the user.
  • Step 8: STOP. This marks the end of the algorithm.

Learn more

Reference