#include #include int* numbers = NULL; int dices = 0; void calc(int diceSum, int leftDices) { if(leftDices <= 0) { numbers[diceSum - dices]++; return; } for(int i = 1; i <= 6; i++) { calc(diceSum + i, leftDices - 1); } } int main(int argAmount, const char** args) { if(argAmount < 3) { if(argAmount > 0) { printf("%s \n", args[0]); } else { puts("... "); } return 0; } dices = atoi(args[1]); int width = atoi(args[2]); if(dices < 1 || dices > 10) { puts("dices must be in the range [1, 10]"); return 0; } else if(width < 1 || width > 200) { puts("print width must be in the range [1, 200]"); return 0; } int range = 6 * dices - dices + 1; numbers = calloc(range, sizeof(int)); calc(0, dices); int max = 0; for(int i = 0; i < range; i++) { if(numbers[i] > max) { max = numbers[i]; } } const char* format = dices == 1 ? "%d: " : "%2d: "; for(int i = 0; i < range; i++) { printf(format, i + dices); int chars = (numbers[i] * width) / max; for(int k = 0; k < chars; k++) { putchar('X'); } putchar('\n'); } free(numbers); return 0; }