C语言实验——打印金字塔

C语言实验——打印金字塔

#include <stdio.h>
int main()  
{  
    int n;  
    int i;  
    int c;  
    int temp;  
    scanf("%d",&n);  
    for(i = 1; i <= n; i++)  
    {  
        for(temp = i; temp < n; temp++)  
        {  
            printf("  ");  
        }  
        for(c = 1; c <= i; c++)  
        {  
            if(i == 1)  
            {  
                printf("%d",c);  
            }  
            else  
                printf("%d ",c);  
        }  
        for(c = i - 1; c > 0; c--)  
        {  
            if(c == 1)  
            {  
                printf("%d",c);  
            }  
            else  
                printf("%d ",c);  
        }  
        printf("\n");  
    }  
    return 0;  
}