Algorithm/문제풀이
[백준] 10815번 - 숫자 카드 (JS)
moaoh
2023. 8. 1. 23:18

26545번: Mathematics
A mathematician has stolen your calculator! Luckily, you know how to code and can write a program that adds together numbers. Write a program that adds together a list of integers.
www.acmicpc.net
문제
A mathematician has stolen your calculator! Luckily, you know how to code and can write a program that adds together numbers. Write a program that adds together a list of integers.
입력
The first line will contain a single integer n that indicates the number of integers to add together. The next n lines will each contain one integer. Your task is to write a program that adds all of the integers together.
출력
Output the resulting integer. The output should be one line containing one integer value.
풀이과정
n만큼의 숫자들을 받아서 모두 더하고 출력해주면 된다.
code
function math() {
let [n, ...arr] = require("fs")
.readFileSync('/dev/stdin')
.toString()
.trim()
.split('\n')
.map(Number);
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
console.log(sum);
};
math();


후기