我有一个程序,它接收一组 16 个数字并将它们打印在 4x4 的网格中。然后我必须检查每一行、每一列和对角线加起来的数字是否相同,但是我不能做这部分,因为我不知道它是如何工作的。任何人都可以帮忙吗?
当前代码:
void getNumbers(int numbers[]){
int idx;
for(int x = 0; x < 17; x++){
cout << "Please enter a number: " << endl;
cin >> idx;
numbers[x] = idx;
}
cout << " " << numbers[0] << " " << numbers[1] << " " << numbers[2] << " " << numbers[3] << endl;
cout << " " << numbers[4] << " " << numbers[5] << " " << numbers[6] << " " << numbers[7] << endl;
cout << " " << numbers[8] << " " << numbers[9] << " " << numbers[10] << " " << numbers[11] << endl;
cout << " " << numbers[12] << " " << numbers[13] << " " << numbers[14] << " " << numbers[15] << endl;
}