题解 | #K形图案#
K形图案
http://www.nowcoder.com/practice/753cc2662d9949fe826a85f815db0ca4
//打印*号的方法
void printXuqiu(int count)
{
for (int i = 0; i <= count; ++i)
{
printf("* ");
if (i == count)
{
printf("\n");
printXuqiu(--count);
}
}
}
//打印下半部分*号的方法
void printXiaBan(int count)
{
int num = 2;
for (int i = 1; i <= count; ++i)
{
for (int j = 0; j < num; ++j)
{
printf("* ");
}
if (num <= count)
{
printf("\n");
num++;
}
}
}
int main()
{
int count = 0;
scanf("%d", &count);
if (count >= 2 && count <= 20)
{
printXuqiu(count);
printXiaBan(count);
}
}