코딩로그
[백준/BOJ/C++] 7595번 Triangles 본문
[문제]
It is not hard to draw a triangle of stars of any given size. For example, a size 5 triangle would look like this (5 stars high and 5 stars wide):
*
**
***
****
*****
Your task is to draw triangles in a number of sizes.
[입력]
Each line of input contains a single positive integer, n, 1 <= n <= 100. The last line of input contains 0. For each non-zero number, draw a triangle of that size.
[출력]
Output consists of triangles of the appropriate sizes. Each triangle is wider at the bottom. There are no gaps between the triangles.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main() {
while(true){
int num;
cin >> num;
if(num == 0) break;
for(int i = 1; i <= num; i++){
for(int j = 1; j <= i; j++){
cout << "*";
}
cout << "\n";
}
}
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
백준/BOJ/C++] 10820번 문자열 분석 (0) | 2021.12.22 |
---|---|
[백준/BOJ/C++] 11655번 ROT13 (0) | 2021.12.22 |
[백준/BOJ/C++] 7596번 MP3 Songs (0) | 2021.12.22 |
[백준/BOJ/C++] 4714번 Lunacy (0) | 2021.12.22 |
[백준/BOJ/C++] 13772번 Holes (0) | 2021.12.22 |