본문 바로가기
알고리즘/백준

[백준] javascript - 2739번 : 구구단

by TLOWAC 2020. 7. 25.
기본적인 문제는 문제풀이 없이 Solution만 작성되어 있습니다.

 

Title

구구단

Description

N을 입력받은 뒤, 구구단 N단을 출력하는 프로그램을 작성하시오. 출력 형식에 맞춰서 출력하면 된다.

 

 [ Example Input ] 

첫째 줄에 N이 주어진다. N은 1보다 크거나 같고, 9보다 작거나 같다.

2

 

 [ Example Output ] 

출력형식과 같게 N*1부터 N*9까지 출력한다.

2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18

Solution

// => 결과값 : 입력값에 따라서 구구단을 출력

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let input = [];
let fixedPoint = 0;

rl.on("line", function (line) {
  input = line.split(' ').map((_) => Number(_));
}).on("close", function () {
  fixedPoint = input[0]

  for (let i = 1; i <= 9; i++) {
    console.log(`${fixedPoint} * ${i} = ${fixedPoint * i}`);
  }
  process.exit();
});


 

글 읽어주셔서 감사합니다.

보다 유익한 컨텐츠를 제작할 수 있도록 노력하겠습니다.

- TLOWAC 이창훈 -

댓글