珂朵莉與黃油麪包(打印圖形練習)

珂朵莉與黃油麪包

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

珂朵莉非常喜歡吃黃油麪包,現在珂朵莉想吃一個大小爲 d 的黃油麪包,你能滿足她麼?

Input

一個正整數 d 。(1<= d <=20)

Output

一個高和寬均爲 2*d-1 的圖形,代表一個大小爲 d 的黃油麪包,詳見樣例。

Sample Input

3

Sample Output

  *
 * *
*   *
 * *
  *
#include <stdio.h>
#include <stdlib.h>
int n;
int main()
{
    int i, j;
    scanf("%d",&n);
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n - i; j++)
            printf(" ");
        printf("*");
        for(j = 1; j <= 2 * i - 3; j++)
            printf(" ");
        if(i != 1)
            printf("*");
        printf("\n");
    }
    for(i = n - 1; i >= 1; i--)
    {
        for(j = 1; j <= n - i; j++)
            printf(" ");
        printf("*");
        for(j = 1; j <= 2 * i - 3; j++)
            printf(" ");
        if(i != 1)
            printf("*");
        printf("\n");
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章