minseo-jung / study-c

0 stars 0 forks source link

삼각형 만들기(3) 3중 for 문... #17

Closed minseo-jung closed 5 years ago

minseo-jung commented 5 years ago
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void triangle_3()
{
    int a;
    int b = 0;
    int c = 0;
    printf("몇단을 쌓으시겠습니까?\n");
    scanf("%d", &a);
    c = a ;
    for (; a > 0; a--)
    {
        for (b = 0; b < c - a; b++)
        {
            printf(" ");
        }
        for (b = 0; b < a; b++)
        {
            printf("*");
        }

        printf("\n");
    }

    return 0;
}

이중포문으로 해결하고 싶었으나 아무리 생각해도 안떠올라 삼중포문으로...ㅠㅠ

wonny25 commented 5 years ago
몇단을 쌓으시겠습니까?
10
**********
 *********
  ********
   *******
    ******
     *****
      ****
       ***
        **
         *
wonny25 commented 5 years ago

이중 포문 버전

int a;
int b = 0;
int c = 0;
printf("몇단을 쌓으시겠습니까?\n");
scanf("%d", &a);
c = a ;
for (; a > 0; a--)
{
    for (b = 0; b < c; b++)
    {
        if (b < c - a) {
            printf(" ");
        } else {
            printf("*");
        }
    }
    printf("\n");
}