21.WAP to find sum of the first n natural number
CODE:
sum=0
n=int(input("Enter the Value on n\n"))
for i in range(1,n+1):
sum+=i
print("Sum of", n,"number is",sum)
OUTPUT:
Enter the Value on n 10 Sum of 10 number is 55
sum=0
n=int(input("Enter the Value on n\n"))
for i in range(1,n+1):
sum+=i
print("Sum of", n,"number is",sum)
OUTPUT:
Enter the Value on n 10 Sum of 10 number is 55
Comments
Post a Comment