add 4th problem
This commit is contained in:
parent
a46eae69fc
commit
8e1bb153e4
32
pset3/4-count.c
Normal file
32
pset3/4-count.c
Normal 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;
|
||||||
|
}
|
Loading…
Reference in a new issue