728x90
문제
두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오.
입력
두 자연수 A와 B가 주어진다. (1 ≤ A, B ≤ 10,000)
출력
첫째 줄에 A+B, 둘째 줄에 A-B, 셋째 줄에 A*B, 넷째 줄에 A/B, 다섯째 줄에 A%B를 출력한다.
예제 입력 1
7 3
예제 출력 1
10
4
21
2
1
내 코드
const readline = require("readline");
const rl = readline.createInterface({
input : process.stdin,
output : process.stdout
});
let input = [];
rl.on("line", function(line){
input = line.split(' ').map((el) => parseInt(el));
}).on("close", function(){
console.log(input[0] + input[1]);
console.log(input[0] - input[1]);
console.log(input[0] * input[1]);
console.log(Math.floor(input[0] / input[1]));
console.log(input[0] % input[1]);
process.exit();
})
결과
> 7 3 10 4 21 2 1 |
728x90
'프로그래밍 > 백준 알고리즘' 카테고리의 다른 글
[백준 / node.js] 2588번: 곱셈 (0) | 2021.07.20 |
---|---|
[백준 / node.js] 10430번: 나머지 (0) | 2021.07.20 |
[백준 / node.js] 1008번: A/B (0) | 2021.07.20 |
[백준 / node.js] 10998번: A x B (0) | 2021.07.20 |
[백준 / node.js] 1001번: A-B (0) | 2021.07.20 |
댓글