본문 바로가기
Problem Solving/boj.kr (JS)

[BOJ / 자바스크립트] 10869 사칙연산

by hoiiiii 2022. 2. 3.

문제 : https://www.acmicpc.net/problem/10869

 

10869번: 사칙연산

두 자연수 A와 B가 주어진다. 이때, A+B, A-B, A*B, A/B(몫), A%B(나머지)를 출력하는 프로그램을 작성하시오. 

www.acmicpc.net

 

두 수를 입력받아 사칙연산을 계산한다.

node.js 에서 입력받기 위해 fs 모듈 또는 readline 모듈을 사용하면 된다. fs는 filesystem의 약자로 fs모듈이 더 빠르기 때문에 기본적으로는 fs 모듈을 사용하면 된다. 단, 컴파일 에러가 발생하는 경우가 있기 때문에 그런 문제에서는 readline을 사용한다.

몫 연산자 ( // )

나머지 연산자 ( % )

 

 

const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().split(' ');
const a = Number(input[0]);
const b = Number(input[1]);

console.log(a+b);
console.log(a-b);
console.log(a*b);
console.log(parseInt(a/b));
console.log(a%b);

댓글