#include
#include
#include
int main()
{
int n,i,j,s;
int **a;
printf("请输入n值: ");
scanf("%d",&n);
fflush(stdin);
a=(int **)malloc(n*n*sizeof(int*));
for(i=0;i
a[i]=(int *)malloc(n*sizeof(int));
}
printf("请输入矩阵成员值: \n");
for(i=0;i
printf("第%d行: \n",i);
for(j=0;j
scanf("%d",&a[i][j]);
fflush(stdin);
}
}
printf("\n");
printf("输入的矩阵为: \n");
for(i=0;i
for(j=0;j
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\n");
for(i=0;i
s=0;
for(j=0;j
}
printf("\n");
for(i=0;i
s=0;
for(j=0;j
}
printf("\n");
s=0;
for(i=0;i
s+=a[i][i];
}
printf("主对角线元素之和为: %d\n",s);
printf("\n");
s=0;
for(i=0;i
s+=a[i][n-1-i];
}
printf("从对角线元素之和为: %d\n",s);
for(i=0;i
getch();
return 1;
}