whatisthis?

๋ฐฑ์ค€ 2739 javascript (node.js) ํ’€์ด ๋ณธ๋ฌธ

ALGORITHM/BOJ (Node.js)

๋ฐฑ์ค€ 2739 javascript (node.js) ํ’€์ด

thisisyjin 2021. 12. 8. 13:14

for๋ฌธ - (1)

 

 


 

๐Ÿ’ก๋ฌธ์ œ

N์„ ์ž…๋ ฅ๋ฐ›์€ ๋’ค, ๊ตฌ๊ตฌ๋‹จ N๋‹จ์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ถœ๋ ฅ ํ˜•์‹์— ๋งž์ถฐ์„œ ์ถœ๋ ฅํ•˜๋ฉด ๋œ๋‹ค.

๐Ÿ“์ž…๋ ฅ

์ฒซ์งธ ์ค„์— N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 9๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค.

๐Ÿ“ˆ์ถœ๋ ฅ

์ถœ๋ ฅํ˜•์‹๊ณผ ๊ฐ™๊ฒŒ N*1๋ถ€ํ„ฐ N*9๊นŒ์ง€ ์ถœ๋ ฅํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 

2

์˜ˆ์ œ ์ถœ๋ ฅ 

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

 

 


< ์ฝ”๋“œ >

let input = require('fs').readFileSync('/dev/stdin');

let N = Number(input);

for(i=1;i<10;i++) {
      console.log(`${N} * ${i} = ${N*i}`);
}

 

i = 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ  i = 9 ๊นŒ์ง€ (i<10)

Number(input) * i ๋ฅผ ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.