백준(Node.js)

백준 10869번: 사칙연산 (Node.js)

심층코드 2025. 6. 25. 06:59

 

사칙연산 

문제

두 자연수 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를 출력한다.

예제 입력 

7 3

예제 출력 

10
4
21
2
1

예제 

const input=require('fs').readFileSync('dev/stdin').toString().trim().split(' ');
const A=parseInt(input[0]);
const B=parseInt(input[1]);

console.log(A+B);
console.log(A-B);
console.log(A*B);
console.log(Math.floor(A/B));
console.log(A%B);

 

공부내용

node.js에서는 /를 하면 소수점 까지 나오므로 Math.floor를 이용하여 몫만 구할 수 있다.

Math.floor는 내림

Math.ceil은 올림

Math.round가 반올림

이다.