#include <iostream.h> #include <iomanip.h> #include <stdio.h> #define m 20 #define h(i,j) ((2*c+2-i)*(i-1)/2+j-i+1) //二维数组中元素在一维数组中的位置 main() { int i=1,j=0,s=0,k,n,c; int a[m*(m+1)/2+1]; a[1]=1; printf("please input the number "); scanf("%d",&n); c=n; while(n>0) { for(k=1;k<=n;k++)n--;//横向赋值 for(k=1;k<=n;k++)n--;//纵向赋值 for(k=1;k<=n;k++)n--;//斜向赋值 } k=0; for(i=1;i<=c;i++) for(j=1;j<=c;j++) { if(i>j) cout<<setw(4)<<"0"; else if(j==c){k++; cout<<setw(4)<<a[k]<<endl; } else } }
|