#include
#include
#include
int main(void)
{
int a[5][5] = {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};
int i, j, iPrv, iCur, iFlag;
iPrv = 0;
iCur = 0;
iFlag = 0;
for (i = 0; i < 5;i++) //对角线之和
{
iPrv += a[i][i];
iCur += a[i][4 - i];
}
if(iCur != iPrv)
{
iFlag = 1;
}
for (i = 0; i < 5;i++) //行之和
{
if(iFlag == 1)
{
break;
}
iCur = 0;
for (j = 0; j < 5;j++)
{
iCur += a[i][j];
}
if(iCur != iPrv)
{
iFlag = 1;
}
}
for (j = 0; j < 5;j++) //列之和
{
if(iFlag == 1)
{
break;
}
iCur = 0;
for (i = 0; i < 5;i++)
{
iCur += a[i][j];
}
if(iCur != iPrv)
{
iFlag = 1;
}
}
if(iFlag == 0)
{
printf("This is magic\n");
}
else
{
printf("Not magic\n");
}
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)