Guys if any one can help me to solve this by type a code please: | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

22nd Jan 2022, 1:24 PM
Karim Karim
2 Answers
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
22nd Jan 2022, 2:07 PM
Jonathan T Rantael
Jonathan T Rantael - avatar
0
s=0 for i in range(1,int(input())+1): s=s+i print(s)
22nd Jan 2022, 7:46 PM
Adi Nath Bhawani
Adi Nath Bhawani - avatar