I'm trying to design a program which outputs a grid of random 0 and 1's, so each position in the grid is equally as likely to have a 1 rather than a 0. I have managed to get the grid sorted with variable sizes but I cant think of a way to randomly assign each position a number. All I have done is assign all positions to 0 so far.
int Lx,Ly,x,y;
printf("Input height\n");
scanf("%d", &Lx);
printf("Input width\n");
scanf("%d", &Ly);
char mat[Lx][Ly];
for(x=0;x<Lx;x++)
for(y=0;y<Ly;y++)
mat[Lx][Ly]='0';
for(x=0;x<Lx;x++)
{
for(y=0;y<Ly;y++)
printf("%c\t",mat[Lx][Ly]);
putchar('\n');
}
return(0);
}
Aucun commentaire:
Enregistrer un commentaire