add 4th problem

This commit is contained in:
juan 2021-10-12 17:25:25 +08:00
parent a46eae69fc
commit 8e1bb153e4
No known key found for this signature in database
GPG key ID: 5C1E5093C74F1DC7

32
pset3/4-count.c Normal file
View file

@ -0,0 +1,32 @@
#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;
}