中易网

C++程序该如何写啊

答案:2  悬赏:50  
解决时间 2021-04-27 18:35
  • 提问者网友:星空下的寂寞
  • 2021-04-27 10:40

For Chinese people, 2008 is a special year. The 29th Olympic Games will be held in Beijing. In order to express our enthusiasm, we draw a big symbol '8'.

Input

Each line of input is a positive integer N (N<=40). The input file is terminated by N=0.

Output

For each input N, you should write a fixed symbol 8 using character '*' with given size N. The width of your drawing is N+1, and the height is 2*N+1. Just see the sample to understand the detail. Output one blank line after each symbol.

Sample Input1 2 3 0 Sample Output** ** ** *** * * *** * * *** **** * * * * **** * * * * ****
最佳答案
  • 二级知识专家网友:转身后的回眸
  • 2021-04-27 12:15
#include <conio.h>
#include <stdio.h>

int main()
{
    int n = 0;
    int a[100];
    int i, j, k;
        scanf("%d", &a[n]);
    while (a[n] != 0)
    {
        n++;
        scanf("%d", &a[n]);
    }
    printf("\n");
    for (i = 0; i < n; i++)
    {
        for (j = -a[i]; j <= a[i]; j++)
        {
            printf("*");
            for (k = 0; k < a[i] - 1; k++)
            {
                if ((fabs(j) == a[i]) || (j == 0))
                {
                    printf("*");
                }
                else
                {
                    printf(" ");
                }
            }
            printf("*\n");
        }
        printf("\n");
    }
        getch();
    return (0);
}


运行结果如下:
全部回答
  • 1楼网友:狠傷凤凰
  • 2021-04-27 13:26
#include <cstdio>void fun_1(int n){ for(int i=0;i<=n;i++) printf("*"); printf("\n");}void fun_2(int n){ for(int i=0;i<=n;i++) if(i==0||i==n) printf("*"); else printf(" "); printf("\n");}int main(){ int n; while(scanf("%d",&n)&&n){ for(int i=0;i<=2*n;i++) if(i==0||i==n||i==2*n) fun_1(n); else fun_2(n); }}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息