提交时间:2019-12-19 20:25:48

运行 ID: 3506

using namespace std; int main() { int num; cout << endl; cin >> num; int **p = new int*[num];//数组大小动态,二维 for (int i = 0; i <num; i++) p[i] = new int[num]; int sum = 0; int number; for (int i = 0; i < num; i++) { cout << (i + 1) << endl; for (int j = 0; j < num; j++){ cout <<< endl; cin >> number; p[i][j] = number; } } for (int i = 0; i < num; i++) { sum += p[i][i] + p[i][num-i-1];//两个对角线元素相加 } cout << sum << endl; return 0; }