// Permutation, total number of cases = R^N #include <stdio.h> #define N 3 #define R 4 int temp[R]; FILE *fp ; void permutation(int value) { int i; if(R==value){ for(i=0; i<R; i++){ printf("%d ", temp[i]); fprintf(fp, "%d ", temp[i]); } printf("\n"); fprintf(fp, "\n"); return; } for(i=1; i<=N; i++){ temp[value]=i; permutation(value+1); } } int main() { fp = fopen("all_cases.txt", "w"); permutation(0); return 0; fclose(fp); }
No comments:
Post a Comment