Skip to main content

Write an Algorithm to find smallest of 3 numbers

Description

This algorithm is designed to find the smallest number among three input numbers. It begins by declaring four containers (variables) to hold values: n1, n2, n3, and MIN. 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 smallest one, storing it in the MIN variable. Finally, it displays the smallest number (MIN) to the user.

Algorithm
Step 1 → START
Step 2 → Declare four variables n1, n2, n3 and MIN.
Step 3 → Read (input) three numbers and store in n1, n2 & n3 respectively
Step 4 → Let MIN = n1
Step 5 → if (n2 < MIN) , then MIN = n2, else next step
Step 6 → if (n3 < MIN), then MIN = n3, else next step
Step 7 → Display (output) MIN as Smallest 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 MIN. 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 MIN = n1. Initialize MIN with the value of n1.
  • Step 5: Check if n2 is smaller than MIN. If yes, update MIN to be n2.
  • Step 6: Check if n3 is smaller than MIN. If yes, update MIN to be n3.
  • Step 7: Display (output) MIN as the Smallest Number. Show the smallest number (MIN) to the user.
  • Step 8: STOP. This marks the end of the algorithm.

Learn more

Reference