- 1
explain this code
#sum of consecutive number N = int(input()) sum = int(N*(N+1)/2) print (sum)
4 Respostas
+ 3
That looks very simple, can you share what you think it means?
+ 1
sum is a bit misleading name for the result of n*(n+1)/2.
result would make more sense.
+ 1
Apollo-Roboto it's the formula for the sum of all numbers from 1 to N.
+ 1
Sd Amar it is a brilliant technique invented by Gauss as a youngster (age 10). The reasoning behind it is a little sophisticated. I explain it in the comments of the code posted here:
https://code.sololearn.com/cxQki21ZMDIX/?ref=app