小编Riy*_*ava的帖子

如何生成模式5 5 5 5 5 4 4 4 4 3 3 3 2 2 1

5 5 5 5 5
  4 4 4 4
    3 3 3
      2 2
        1
Run Code Online (Sandbox Code Playgroud)

如何使用c生成模式以上的模式我试过这个

int i, j, N;

scanf("%d", &N);

for(i=N; i>=1; i--)
{
    //Logic to print spaces
    for(j=N; j>i; j--)
    {
        printf(" ");
    }

    //Logic to print numbers
    for(j=1; j<=i; j++)
    {
        printf("%d ", i);
    }
    for(j=N; j>i; j--)
    {
        printf(" ");
    }

    printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

c

-3
推荐指数
1
解决办法
884
查看次数

标签 统计

c ×1