Skip to main content

Write an Algorithm to Calculate & Print sum of N numbers

Description

This algorithm is designed to calculate the sum of numbers starting from 1 up to a given value, N. It begins by declaring three containers (variables) to hold values: N, count, and SUM. The user is prompted to input a value for N. The algorithm then initializes count and SUM, followed by iterating through a loop, adding each count to the SUM. Once the loop is complete, it displays the total sum (SUM) to the user.

Algorithm
Step 1 → START
Step 2 → Declare three variables N, count, SUM
Step 3 → Read (input) value of N
Step 4 → Initialize count = 1 and SUM = 0
Step 5 → if (count <= N) , then goto next step, else go to step 9
Step 6 → SUM = SUM + count
Step 7 → count = count + 1
Step 8 → go to step 5
Step 9 → Display (output) the value of SUM.
Step 10 → STOP

What does this mean ?

  • Step 1: START. This marks the beginning of the algorithm.
  • Step 2: Declare three variables N, count, and SUM. These are containers to hold values.
  • Step 3: Read (input) value of N. Get a value from the user and store it in N.
  • Step 4: Initialize count = 1 and SUM = 0. Set the initial values of count and SUM.
  • Step 5: Check if count is less than or equal to N. If yes, proceed to the next step. If not, go to step 9.
  • Step 6: SUM = SUM + count. Increment SUM by the current value of count.
  • Step 7: Increment count by 1. Increase count for the next iteration.
  • Step 8: Go to step 5. Loop back to step 5 and repeat steps 5-7 until count is within the specified range.
  • Step 9: Display (output) the value of SUM. Show the total sum (SUM) to the user.
  • Step 10: STOP. This marks the end of the algorithm.

Learn more

Reference