Skip to content

Instantly share code, notes, and snippets.

@ofelix03
Created February 21, 2021 17:46
Show Gist options
  • Save ofelix03/c4c8c278410c26906da2a447e921ac2b to your computer and use it in GitHub Desktop.
Save ofelix03/c4c8c278410c26906da2a447e921ac2b to your computer and use it in GitHub Desktop.
A program to find the sum of N numbers
"""
Algorithm to find the sum of N numbers
Steps
1. Start
2. Declare and assigned variables, i=0, sum=0, N
3. Enter how many numbers you want to find their sum (N)
4. Enter number (num)
5. Add number(num) to sum ie sum = sum + num
6. Increase i by 1 ie i = i + 1
7. Check if i <= N-1, repeat step 4 to 6
8. Display sum
9. End
"""
sum = 0
i = 0
n = input("Enter how many numbers to find their sum: ")
n = int(n)
for i in range(0, n):
num = input("Enter number ({}): ".format(i+1))
sum = sum + int(num)
print("Sum = {}".format(sum))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment