一个魔法正方形矩阵是一个n×n的矩阵,其中整数1,2,3……n2出现且仅仅出现一次,而每一行、每一列和对角线上元素的和都相等。例如,下面就是一个5×5的魔法正方形,所有的行、列以及对角线上的和都为65.
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
代码:
#include<iostream>
#include<cmath>
#include<cassert>
using namespace std;
int sqrt1(int n);
struct magicNum
{
int value;
bool flag;
};
void main()
{
cout<<"Please input the random odd number n:"<<endl;
int n,row,col;
cin>>n;
n=n*n;
//n=25;
asse