+ 1

My code to find the sum of first x natural numbers

Please check and correct me https://code.sololearn.com/c88nm8EtOIev/?ref=app

13th Oct 2020, 2:57 PM
roshan roy
3 odpowiedzi
+ 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
13th Oct 2020, 8:50 PM
Brian
Brian - avatar
+ 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.
14th Oct 2020, 4:16 AM
Brian
Brian - avatar
13th Oct 2020, 4:36 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar