프로그래머스 (JS)/Lv. 0
[Programmers] 120823번 - 직각삼각형 출력하기
hodo-
2023. 3. 2. 20:35
Problem
"*"의 높이와 너비를 1이라고 했을 때, "*"을 이용해 직각 이등변 삼각형을 그리려고합니다. 정수 n 이 주어지면 높이와 너비가 n 인 직각 이등변 삼각형을 출력하도록 코드를 작성해보세요.
Solution
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let input = [];
rl.on('line', function (line) {
input = line.split(' ');
}).on('close', function () {
for(let i = 1; i <= Number(input[0]); i++){
console.log("*".repeat(i));
}
});
"*".repeat(i) : "*"를 i만큼 반복