練習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的判題依據是需要仔細閱讀的,畢竟是機器判題,需要嚴格遵循規則。

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