diff --git a/f2.c b/f2.c new file mode 100644 index 0000000..064b7a4 --- /dev/null +++ b/f2.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +int used[10]; + +void row(int row[]){ + int nums[3]; + int numcount=0; + while(numcount < 3){ + int num=rand()%9+1; + if(!used[num]){ + nums[numcount++]=num; + used[num]=1; + } + } + int i; + for ( i=0;i < 3; i++) { + int index; + do{ + index=rand()%9; + }while(row[index] != 0); + row[index]=nums[i]; + } +} +int main(){ + int i,j; + int a[10][10]; + srand((unsigned)time(NULL)); + for ( i = 0; i < 9; i++){ + for( j=0; j < 9; j++){ + a[i][j]=0; + } + if(i % 3 == 0) + memset(used, 0, sizeof(used)); + row(a[i]); + } + + for(i=0;i < 9;i++){ + for( j=0;j < 9;j++) { + printf("%d ",a[i][j]); + + } + printf("\n"); + } + return 0; +}