Print the sum from 1 to N

Problem

Write a program that outputs the sum from 1 to N when a natural number N is input.

input

A natural number N less than or equal to 20 is entered in the first line.

6

10

output

Prints the sum from 1 to N on the first line.

21

55

Solution

using for

function solution(n) {
	let answer = 0;
	for (let i = 1; i <= n; i++) {
		answer += i;
	}
	return answer;
}