练习5-3 数字金字塔

#include <stdio.h>

void pyramid( int n );

int main()
{    
    int n;

    scanf("%d", &n);
    pyramid(n);

    return 0;
}
void pyramid( int n )
{  
    int i,j,k,m;  
    m = n;  
    for(i=1;i<=n;i++,m--)
    {  
        j=m-1; 	//the last line don't need the space! That means the space is one less than the number.
        for(;j>0;j--)  
            printf(" ");  
        for(k=i;k>0;k--)  
            printf("%d ", i);  // PTA receives the space after the number.
        printf("\n");  
    }  
}  

不得不说PAT的判题依据是需要仔细阅读的,毕竟是机器判题,需要严格遵循规则。

猜你喜欢

转载自blog.csdn.net/qq_31912571/article/details/82919713
今日推荐