본문 바로가기

Development/C / C++

[C언어 연습문제] 별로 사선 채우기

환경 : Windows 7 64bit / Visual Studio 2013 Express

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    int width = -1;
    int height = -1;
    int gap = -1;

    printf_s("Input Width : ");
    scanf_s("%d", &width);
    
    printf_s("Input Height : ");
    scanf_s("%d", &height);

    printf_s("Input Gap : ");
    scanf_s("%d", &gap);

    int gapPrint = 0;

    for (int printCount = 0; printCount < height * width; printCount++)
    {
        if ((printCount % width) == 0)
        {
            printCount++;
            printf_s("\n");
            for (int gapCount = gapPrint; gapCount < gap; gapCount++)
            {
                printf_s(" ");
            }
            if (gapPrint == gap)
            {
                gapPrint = 0;
            }
            else
            {
                gapPrint++;
            }
        }
        printf_s("*");
        for (int gapCount = 0; gapCount < gap; gapCount++)
        {
            if ((printCount % width) == 0)
            {
                printf_s("\n");
            }
            printf_s(" ");
        }
    }

    return 0;
}

Output

 

 

태그