SOLUTION: If you have 10 questions, and 2 choices per question, then I will have 3^10=59049 possible answer sheets.
I would like to have a code in any programming language to generate for
Question 1058173: If you have 10 questions, and 2 choices per question, then I will have 3^10=59049 possible answer sheets.
I would like to have a code in any programming language to generate for me these answer sheets up to the last one.
e.g answer sheet 1 can look like;
1.A
2.C
3.A
4.A
5.B
6.C
7.C
8.A
9.A
10.B Found 2 solutions by math_helper, ikleyn:Answer by math_helper(2461) (Show Source): You can put this solution on YOUR website! The program to do 3 choices per question, with 10 questions, is below. Unlike the 2 choice version, this version uses an array to hold the current answer key and after printing the current key, it increments the first answer, if that goes past the 3rd choice, it resets that value back to 0 and carries over the change to the next entry (and so on until it reaches an entry that doesn't carry). In this way the array will walk across all possible answer keys.
………………………………………………. cut ……………………………………………...
#include stdio.h // surround stidio.h with less than, greater than
#include math.h // surround math.h with less than, greater than
int main(int argc, char **argv)
{
int i,j,k, key[10];
int n_max;
// Zero out the ans key, key[k]=0,1,2 ==> A,B,C respectively
for(k=0; k<10; k++) {
key[k] = 0;
}
n_max = (int)pow(3, 10);
// Next line is "for i equals 0 semicolon i less than n max semicolon i plus plus"
for(i=0; i
// Print ans sheet corresponding to key[]
printf("Ans sheet %d\n", i+1);
for(j=0; j<10; j++) {
printf("%2d. %c\n", j+1, key[j]+'A');
}
// Generate next ans key
for(k=0; k<10; k++) {
key[k]++;
if (key[k] > 2) {
key[k] = 0;
}
else {
// Exit loop once we have no more carries
break;
}
}
}