Hello! I'm new to programming, and currently having trouble with a C program. In essence, I am suppose to make a magic square program, and in order to do so I thought that I would have to create a 3x3 matrix, then randomize the numbers in each slot, without any overlapping, and keep looping that until every row, column and diagnals equals one another. I'm sure there are other more efficient ways, but this is all I could think of. So far I have
Code:
#include <stdio.h>
#include<stdlib.h>
#define N 3
int main(void)
{
srand((unsigned)time(NULL));
int b[N][N], int i, int j;
for( ){
/* need to randomize numbers 1-9 here in matrix but I don't know how*/
if(b[0][0]+b[1][0]+b[2][0]=b[0][1]+b[1][1]+b[2][1]=b[0][2]+b[1][2]+b[2][2]=b[0][0]+b[0][1]+b[0][2]=b[1][0]+b[1][1]+b[1][2]=b[2][0]+b[2][1]+b[2][2]=b[0][0]+b[1][1]+b[2][2]=b[2][0]+b[1][1]+b[0][2])
printf("/* how do you print the current matrix?*/");
break;
else continue;}
}
and simply want the result to be something like
% ./a.out
4 3 8
9 5 1
2 7 6
Please help me!