求大神找错
#include <stdio.h>#include <stdlib.h>
void Readnum(int num[5][5]);
int Judge(int num[5][5]);
int main()
{
int n,num[5][5];
Readnum(num);
n=Judge(num);
if(n)
printf("It is a magic square!");
else
printf("It is not a magic square!");
return 0;
}
void Readnum(int num[5][5])
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
scanf("%d",&num[i][j]);
}
}
}
int Judge(int num[5][5])
{
int y,sum1,sum2,sum3,sum4,i,j,sum;
sum1=0;sum2=0;sum3=0,sum=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
sum=sum+num[i][j];
}
}
y=sum%5;
if(y!=0)
return 0;
y=sum/5;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
sum1=sum1+num[i][j];
}
if(sum1!=y)
return 0;
else sum1=0;
}
for(j=0;j<5;j++)
{
for(i=0;i<5;i++)
{
sum2=sum2+num[i][j];
}
if(sum2!=y)
return 0;
else sum2=0;
}
for(i=0;i<5;i++)
{
sum3=sum3+num[i][i];
}
if(sum3!=y)
return 0;
for(i=4;i>0;i--)
{
sum4=sum4+num[4-i][i];
}
if(sum4!=y)
return 0;
return 1;
}
实例:输入举例1:
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
输出举例1:
It is a magic square!
输入举例2:
2 24 1 8 15
23 5 4 14 16
4 6 13 20 22
10 11 19 21 3
11 18 1 2 9
输出举例2:
It is not a magic square!