Saturday, 28 August 2021

Python Program : 8 : Compute sum of natural numbers from one to n number.

PROGRAM :-
import math
SUM = 0
n = int(input("Enter any integer value : "))
if n > 0:
    for i in range(1,n+1):
        SUM = SUM + i
    print("Sum of the numbers upto ",n,":",SUM)
elif n == 0:
    print("Sum is 0")
else:
    print("Enter any + ve value")

VIDEO LINK : -


No comments:

Post a Comment

Note: only a member of this blog may post a comment.