diff --git a/pset3/4-count.c b/pset3/4-count.c new file mode 100644 index 0000000..1321550 --- /dev/null +++ b/pset3/4-count.c @@ -0,0 +1,32 @@ +#include + +int main(void) { + // Initialize counts + int count3 = 0, count5 = 0, count7 = 0; + int count = 0; + + // Get input + int input; + scanf("%d", &input); + + while (input != 0) { + // Add up counts + if ((input % 3 == 0) && (input % 5 != 0) && (input % 7 != 0)) { + count3++; + } else if ((input % 5 == 0) && (input % 7 != 0) && (input % 3 != 0)) { + count5++; + } else if ((input % 7 == 0) && (input % 5 != 0) && (input % 3 != 0)) { + count7++; + } + + count++; + + scanf("%d", &input); + } + + // Print answers + printf("%.2f%%\n%.2f%%\n%.2f%%\n", 100 * count3 / (float)count, + 100 * count5 / (float)count, 100 * count7 / (float)count); + + return 0; +}