【发布时间】:2015-04-25 22:54:52
【问题描述】:
我必须为 C 代码中的查找表生成所有可能的输入。我确信它必须以递归方式完成,但我找不到任何方法。你有什么建议吗?谢谢
int main()
{
int i,j,k;
int M,N;
int comb;
FILE *fp;
printf("Insert M and N values \n");
scanf("%d", &M);
scanf("%d", &N);
comb = (int) pow(2.0,M);
int A[comb][M];
int B[comb][N];
time_t t;
srand((unsigned) time(&t));
fp = fopen("lut.txt","w");
fprintf(fp, "INPUTPINS - %d\n", M);
fprintf(fp, "OUTPUTPINS - %d\n", N);
for (i=0; i< comb; i++)
{
for(j= 0; j<M; j++)
{
fprintf(fp,"%d", A[i][j]);
}
fprintf(fp, " - ");
for (k=0; k<N; k++)
{
B[i][k] = rand()%2;
fprintf(fp, "%d", B[i][k]);
}
fprintf(fp,"\n");
}
fclose(fp);
return 0;
}
我需要为我的矩阵 A 生成值,它将包含所有可能的 2^n 输入,而输出将是随机的。
【问题讨论】:
-
只有在您与我们分享您的一些代码时,才能提出建议。