Merge pull request #1419 from juanarbol/juanarbol/add-gauss-sum-alg
Add Gauss sum or sum of k naturals.
This commit is contained in:
16
snippets/sumN.md
Normal file
16
snippets/sumN.md
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
title: sumN
|
||||
tags: math,beginner
|
||||
---
|
||||
|
||||
Sums all the numbers between 1 and `n`.
|
||||
|
||||
- Use the formula `(n * (n + 1)) / 2` to get the sum of all the numbers between 1 and `n`.
|
||||
|
||||
```js
|
||||
const sumN = n => (n * (n + 1)) / 2;
|
||||
```
|
||||
|
||||
```js
|
||||
sumN(100); // 5050
|
||||
```
|
||||
Reference in New Issue
Block a user