求指正, 编辑没有报错
#include "iostream.h"int main()
{
int i,j,n,sum=0;
cout<<" "<<endl;
cin>>n;
int **a;
a = new int* [n];
a[0] = new int[n * n];
for(i=0; i<n; i++)
{
a[i] = a[i-1] + n;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cout<<"a["<<i<<"]["<<j<<"]=";
cin>>a[i][j];
//cout<<'\n';
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cout<<a[i][j]<<'\t';
}
cout<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if (i=j)
sum+=a[i][j];
}
}
cout<<"这个"<<n<<"行"<<n<<"列的矩阵的对角线元素之和为: "<<sum<<endl;
delete[] a[0];
delete[] a;
return 0;
}