-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2741-number.js
More file actions
44 lines (36 loc) · 949 Bytes
/
2741-number.js
File metadata and controls
44 lines (36 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//{문제}
//자연수 N이 주어졌을 때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.
//코드
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("line", function (line) {
const input = line;
const output = [];
for (let i = 1; i <= input; i++) {
output[i - 1] = i;
}
console.log(output.join("\n"));
rl.close();
}).on("close", function () {
process.exit();
});
//다른 방법
// const readline = require('readline');
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });
// rl.on('line', function(line) {
// const input = Number(line);
// let str = '';
// for(let i=1; i <= input; i++){
// str+=(i+'\n');
// }
// console.log(str.slice(0, -1));
// rl.close();
// }).on("close", function() {
// process.exit();
// });