/*program to check if given square is a magic square or not*/ /*A magic square is a square array of positive integers such that the sum of each row, column, and diagonal is the same constant*/ #include int ifMagicSq(int *a,int); int main() { int order=4; int *a; a=(int *)malloc(sizeof(int )*(order*order)); /*enter a matrix which is a magic square - modify this to check if code works*/ *(a+0)=16; *(a+1)=3; *(a+2)=2; *(a+3)=13; *(a+4)=5; *(a+5)=10; *(a+6)=11; *(a+7)=8; *(a+8)=9; *(a+9)=6; *(a+10)=7; *(a+11)=12; *(a+12)=4; *(a+13)=15; *(a+14)=14; *(a+15)=1; if(ifMagicSq(a,4)==1) puts("The given square is a magic square"); else puts("The given square is not a magic square"); return(0); } int ifMagicSq(int *a,int order) { int i,j,flag,sum,checksum; /*initilise checksum to sum of principal diagonal*/ for(i=0,checksum=0;i=0;i--,j++) sum=sum+*((int *)(a+j+i)); if(sum!=checksum) return(0); /*check for rows*/ for(i=0;i