Skip to main content

Write an Algorithm to subtract two numbers

Description

This algorithm is designed to subtract one number (n2) from another number (n1). It starts by declaring three containers (variables) to hold values: n1, n2, and diff. The user is prompted to input two numbers, which are stored in n1 and n2. The algorithm then subtracts n2 from n1 and stores the result in a variable called "diff". Finally, it displays the result of the subtraction (diff) to the user.

Algorithm
Step 1 → START
Step 2 → Declare three variables n1, n2 and diff.
Step 3 → Read (input) two numbers and store in n1 & n2 respectively
Step 4 → Subtract n1 & n2 and store result in diff i.e. diff = n1 - n2
Step 5 → Display (output) result i.e. diff
Step 6 → STOP

What does this mean ?

  • Step 1: START. This marks the beginning of the algorithm.
  • Step 2: Declare three variables n1, n2, and diff. These are containers to hold values.
  • Step 3: Read (input) two numbers and store in n1 & n2 respectively. Get numbers from the user and store them in n1 and n2.
  • Step 4: Subtract n1 and n2 and store the result in diff. Perform subtraction with the numbers in n1 and n2, and store the result in diff.
  • Step 5: Display (output) the result, i.e., diff. Show the result to the user.
  • Step 6: STOP. This marks the end of the algorithm.

Learn more

Reference