提交时间:2019-12-14 19:13:36
运行 ID: 3241
#include <iostream> using namespace std; int main() { int num; 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 << (j + 1) << 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; }