ADD file via upload

main
p5fohke9s 3 weeks ago
parent 0734407cfa
commit 5acb5136d2

47
f2.c

@ -0,0 +1,47 @@
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
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;
}
Loading…
Cancel
Save