/** * Program to calculate sequence of random numbers and count result of * computing, for each of them, remainder when divided by selected value. */ #include #include int main(void) { int how_many; int divisor; int num; printf("how many numbers?\n"); if (scanf("%d", &how_many) != 1) { printf("invalid\n"); return EXIT_FAILURE; } printf("divisor (> 0)?\n"); if ((scanf("%d", &divisor) != 1) || (divisor <= 0)) { printf("invalid\n"); return EXIT_FAILURE; } int remainders[divisor]; for (int i = 0; i < divisor; ++i) { remainders[i] = 0; } for (int i = 0; i < how_many; ++i) { num = rand(); remainders[num % divisor] += 1; } for (int i = 0; i < divisor; ++i) { printf("%d with remainder %d\n", remainders[i], i); } return EXIT_SUCCESS; }