#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/*
(0,0) (0,1) (0,2)
(1,0) (1,1) (1,2)
(2,0) (2,1) (2,2)
*/
int main(int argc, char *argv[])
{
srand(time(NULL));
int i,j;
char table[3][3]={{1,2,3},{4,5,6},{7,8,9}};
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
int r=rand()%9;
printf("r=%d\n",r);
int m=r/3;
printf("m=%d\n",m);
int n=r%3;
printf("n=%d\n",n);
int t=table[i][j];//00 01 02
printf("t=%d\n",t);
table[i][j]=table[m][n];
table[m][n]=t;
printf("t=%d\n",table[m][n]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",table[i][j]);
}
printf("\n");
}
return 0;
}
沒有留言:
張貼留言