Problem 31. pattern3.js (*** Revise***)

 /*Question

Given a positive integer n, generate the following format.
suppose n is 3, then the format is

1
1 2
1 2 3


Input: One line containing a positive integer, denoting n .
Output: Above described format.

Example:
Input:
5

output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Algorithm:
1) Read the input number
2) Print the pattern
*/

let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split('\n');

function readLine() {
idx++;
return data[idx - 1].trim();
}
//..........................................................................................

let num = parseInt(readLine()); // 3

for (let i = 1; i <= num; i++) {

let tmp = '';

for (let j = 1; j <= i; j++) {
tmp = tmp + ' ' + j;

}

console.log(tmp);
console.log();

}

TERMINAL:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node pattern3.js <input.txt 1 1 2 1 2 3 Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$




Comments

Popular posts from this blog

Problem 33. patter122333.js

Problem 38. diamond.js

Problem 16. chocolatebills.js