+ 1
My code to find the sum of first x natural numbers
Please check and correct me https://code.sololearn.com/c88nm8EtOIev/?ref=app
3 Answers
+ 3
I wrote this program to solve the problem without looping. It is similar in principle to the formula given by Jan Markus, though I generalized it to work between any range of integers. I included a brief explanation in the comments at the end to show how it works.
https://code.sololearn.com/cxQki21ZMDIX/?ref=app
+ 2
Jan Markus, excellent!
I considered exploring that approach to see whether it could simplify the code, but I hadn't done the math yet. Much appreciated.