문제는 하나의 루프와 계속 문을 사용하여 패턴을 표시하는 것입니다.
알고리즘
START Step 1 -> declare start variables i and j to 0 with number of rows in n to 6 Step 2 -> Loop For i=1 and i<=n IF j<i Print * Increment j by 1 Continue End IF IF j=1 Print \n Set j=0 Increment i by 1 End IF Step 3 -> End For Loop STOP
예시
#include <stdio.h>
int main() {
int i, j=0;
int n = 6;
for ( i = 1; i <= n; ) {
if( j < i ) {
printf("*");
j++;
continue;
}
if(j == i) {
printf("\n");
j = 0;
i++;
}
}
return 0;
} 출력
위의 프로그램을 실행하면 다음 출력이 생성됩니다.
* ** *** **** ***** ******