35.2k views
2 votes
Write a c program to print all possible marking schemes of 15 questions each with 3.

1 Answer

4 votes

Answer:

#include <math.h>

#include <stdio.h>

#include <string.h>

#define BASE 3

#define NRQUESTIONS 15

void toABC(int n, char* buf, int base, int size) {

memset(buf, 'A', size);

buf[size] = 0;

while (n && size) {

buf[--size] = 'A' + (n % base);

n /= base;

}

}

int main()

{

char buf[16];

for (int i = 0; i < pow(BASE, NRQUESTIONS); i++) {

toABC(i, buf, BASE, NRQUESTIONS);

printf("%s\\", buf);

}

}

Step-by-step explanation:

Assuming 3 is the number of possible answers to choose from for each question.

I tackled this by having an integer counter enumerate all values from 0 to 3^15, and then convert each integer to a base-3 representation, using ABC in stead of 012.

User Thunderbeef
by
5.4k points