标签:mic include 二维数组 main turn 输出 i++ return includes
int main(){
int i,j,m,n,k,p=0;
printf("请问要输入几级方阵:");
scanf("%d",&n);
j=(nn+n)/2;
int a[j],b[n][n];
for(i=0;i<j;i++){
printf("请问要输入数据:");
scanf("%d",&a[i]);
}
printf("输出下三角方阵:\n");
p=1; //代表层数
for(i=0;i<j;i++){
k=0;
while(k<p){
printf("%d\t",a[i]);
k++;
i++;
}
i--;
k=p;
while(k<n){
printf("\t");
k++;
}
printf("\n");
p++;
}
printf("输出上三角方阵:\n");
p=1;
for(i=0;i<j;i++){
k=1;
while(k<p){
printf("\t");
k++;
}
k--;
while(k<n){
printf("%d\t",a[i]);
k++;
i++;
}
i--;
printf("\n");
p++;
}
printf("将一维数组放在二维数组中,数据如下:\n");
m=0;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
b[i][j]=a[m];
if(m>=(nn+n)/2)
b[i][j]=0;
m++;
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("\n");
printf("请输出对称方阵:\n");
for(i=0;i<n;i++){
for(j=0;j<n;j++){
b[j][i]=b[i][j];
printf("%d\t",b[i][j]);
}
printf("\n");
}
return 0;
}
标签:mic include 二维数组 main turn 输出 i++ return includes
原文地址:https://www.cnblogs.com/lusilin/p/10828674.html