#include "stdio.h" int main() { int n,i,j; while(scanf("%d",&n)) { for(i=1; i<=n; i++) { for(j=1; j<=n-i; j++) //畫空格 printf(" "); for(j=1; j<=i; j++) printf("%d",j);//輸出從1到n for(j=i-1; j>=1; j--) printf("%d",j);//輸出從n-1到1 printf(" "); } for(i=n-1; i>=1; i--) { for(j=1; j<=n-i; j++) //畫空格 printf(" "); for(j=1; j<=i; j++) printf("%d",j);//輸出從1到n for(j=i-1; j>=1; j--) printf("%d",j);//輸出從n-1到1 printf(" "); } } return 0; }
#include "stdio.h" int main() { int n,i,j; while(scanf("%d",&n)) { for(i=1; i<=n; i++) { for(j=1; j<=n-i; j++) //畫空格 printf(" "); for(j=1; j<=i; j++) printf("%d",j);//輸出從1到n for(j=i-1; j>=1; j--) printf("%d",j);//輸出從n-1到1 printf(" "); } for(i=n-1; i>=1; i--) { for(j=1; j<=n-i; j++) //畫空格 printf(" "); for(j=1; j<=i; j++) printf("%d",j);//輸出從1到n for(j=i-1; j>=1; j--) printf("%d",j);//輸出從n-1到1 printf(" "); } } return 0; }