n natural numbers

Solutions on MaxInterview for n natural numbers by the best coders in the world

showing results for - "n natural numbers"
Erika
06 Apr 2019
1Method 1:
2
3num = int(input("Enter the Number:"))
4value = 0
5for i in range(1, num+1):
6    value = value + i
7
8print("Sum of N natural numbers:", value)
9
10
11Method 2:
12
13num = int(input("Enter the Number:"))
14sum = (num * (num+1))/2
15print("The Sum of N natural Number is {}".format(sum))
16
17# This code is contributed by Shubhanshu Arya (Prepinsta Placement Cell Student) 
18