How to calculate the sum of the first N natural numbers in Node.js

1 Answer

0 votes
// In mathematics, the natural numbers are 1, 2, 3, 4, and so on
// 1 + 2 + 3 + 4 + ... + N

let n = 13, sum = 0;
 
sum = n / 2 * (n + 1);
         
console.log("The sum is: " + sum);



/*
run:  

The sum is: 91

*/

 



answered Nov 12, 2024 by avibootz

Related questions

2 answers 248 views
2 answers 242 views
2 answers 208 views
2 answers 529 views
2 answers 222 views
2 answers 207 views
...