0
Guys if any one can help me to solve this by type a code please:
No one likes homework, but your math teacher has given you an assignment to find the sum of the first N numbers. Let’s save some time by creating a program to do the calculation for you! Take a number N as input and output the sum of all numbers from 1 to N (including N). Sample Input 100 Sample Output 5050 Explanation: The sum of all numbers from 1 to 100 is equal to 5050.
2 Antworten
0
the sum of all numbers from 1 to 100 is actually 4950, not 5050. 5050 if you add 100 to it.
the sum from 1 to 100 = 4950
4950 + 100 = 5050
so you need to loop from 1 to 100 to get 4950, then after the loop add 100 to get 5050
0
s=0
for i in range(1,int(input())+1):
s=s+i
print(s)