+ 1
suppose you have this array as consecutive numbers and you need to find it sum array = (1,2,3,4) using for loop(or any) traverse the array and add each digit to a variable to get the sum or much better n = 4 for i = 1, i <= n; i++ s += i s is the sum or using maths n * (n + 1) / 2
16th Mar 2021, 6:41 AM
minirkk
minirkk - avatar
0
n = 4 print(sum(i for i in range(1, n+1)))
16th Mar 2021, 6:44 AM
Tomas Konecny
16th Mar 2021, 7:08 AM
Tomas Konecny
16th Mar 2021, 8:01 AM
visph
visph - avatar
- 1
N = int(input()) count = N x = range(1, N +1) for i in x: N = i + N print(N - count)
18th May 2021, 8:09 AM
Ислам Алб
Ислам Алб - avatar