Write a program to calculate sum of numbers from 1 to 100 without using loop statements. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Write a program to calculate sum of numbers from 1 to 100 without using loop statements.

You are free to choose any programming language. ======================= using only one statement, you have to print the sum of numbers from 1 to 100. Happy Coding!

22nd Mar 2018, 11:00 AM
Amit Kumar Maurya
Amit Kumar Maurya - avatar
4 Answers
+ 7
# given n = 100 print((1+n)*n/2)
22nd Mar 2018, 11:50 AM
Pedro Demingos
Pedro Demingos - avatar
+ 3
Jay Matthews’ code includes the solution I gave, and he answered first. I think his answer should be marked as best ☺️
22nd Mar 2018, 2:00 PM
Pedro Demingos
Pedro Demingos - avatar
+ 1
python: lambda n: sum(range(n+1))
22nd Mar 2018, 11:28 AM
Amaras A
Amaras A - avatar
+ 1
num =100 print(num*(num+1)/2)
22nd Mar 2018, 9:10 PM
yogesh