+ 2
How to write a program to print the sum of first n natural numbers
4 Answers
+ 6
have a sum variable, iterate from 1 to n, and add each number to the sum variable
+ 4
or use the formula n*(n+1)//2
+ 2
a better approach would be to directly use the formula -
n*(n + 1) / 2
+ 1
ok thanks