Computer Science, asked by banerjeesubhojit92, 3 months ago

python programming to find the sum of natural number​

Answers

Answered by anindyaadhikari13
2

Answer:

This is the Python program to find the sum of natural numbers upto n terms.

1. Using loop.

n=int(input("Enter limit - "))

s=0

for i in range(1,n+1):

s+=i

print("Sum: ",s)

2. Using sum function.

n=int(input("Enter limit - "))

s=sum([i for i in range(1,n+1)])

print("Sum: ",s)

Algorithm:

  1. START.
  2. Accept the limit (n).
  3. Initialise s = 0
  4. Iterate a loop in the range i = 1 to n.
  5. Add the value of 'i' in s.
  6. Display the value of s.
  7. STOP.

See the attachment for output .

Attachments:
Similar questions