Problem 33. patter122333.js
/*Question
Pattern122333
Write a program to make such a pattern like right angle triangle with a
number which will repeat a number in a row, as shown below.
For n = 4, the pattern should be like:
1
22
333
4444
Input
One Integer, denoting n.
Output
The required pattern
Example
Input1:
5
Output1:
1
22
333
4444
55555
*/
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 n = parseInt(readLine()); // 5
for (let i = 1; i <= n; i++) // responsible for the rows i,e 5 rows
{
let j = 1 // initialization of while loop
let temp = ''
while (j <= i) {
temp = temp + i;
j++;
}
console.log(temp);
}
TERMINAL:
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$ node patter122333.js <input.txt
1
22
333
4444
55555
Nobins-MacBook-Pro:STOC_MODULE 11SEPT 2022 nobinpunyo$
Comments
Post a Comment