提交时间:2019-12-20 19:52:36

运行 ID: 3593

#include<iostream> using namespace std; int main() { int n; int **a; int sum = 0; cin >> n; a = new int*[n]; for (int i = 0; i < n; i++) { a[i] = new int[n]; for (int j = 0; j < n; j++) cin >> a[i][j]; } for (int i = 0; i < n; i++) { sum = sum + a[i][i]; } cout<<sum<<endl; for (int i = 0; i<n; i++) { delete[]a[i]; } delete[]a; return 0; }