합 (8393)
Created:
팩토리얼의 덧셈 버전..?
Bash
Bash 1
2
3
4
5
6
read n
s=0
for ((i=1; i<=n; i++)); do
((s += i))
done
echo $s
C
C 1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
int main(void) {
int n, s = 0;
scanf("%d", &n);
for (int i=1; i<=n; i++) {
s+=i;
}
printf("%d\n", s);
return 0;
}
Node.js
JavaScript 1
2
3
4
5
6
7
let n = Number(require("fs").readFileSync(0).toString().trim());
let s = 0;
while (0 < n) {
s += n;
n--;
}
console.log(s);
PHP
PHP 1
2
3
4
<?php
fscanf(STDIN, "%d", $n);
echo array_sum(range(1, $n));
?>
Python3
Python 1
2
n = int(input())
print( sum(range(n+1)) )
Ruby
Ruby 1
2
n = gets.chomp.to_i
puts (1..n).sum()