BUPT-homework/semester1/pset3/4-count.c

33 lines
701 B
C

#include <stdio.h>
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;
}