/* Example: Vowel Counting Goal: Multiple selection Author: Peter Brusilovsky */ #include void main() { char c; int a, e, i, o, u, others; int pa, pe, pi, po, pu, pothers; float total; a = e = i = o = u = others = 0; /* Accumulating counters in the loop */ while ((c = getchar()) != EOF) if (c == 'a') a++; else if (c == 'e') e++; else if (c == 'i') i++; else if (c == 'o') o++; else if (c == 'u') u++; else if (c != '\n') others++; /* Calculating percentages */ total = a + e + i + o + u + others; pa = (a / total) * 100; pe = (e / total) * 100; pi = (i / total) * 100; po = (o / total) * 100; pu = (u / total) * 100; pothers = (others / total) * 100; /* Printing results */ printf("\nNumbers of characters:\n\n"); printf("a %d; e %d; i %d; o %d; u %d; rest %d\n", a, e, i, o, u, others); printf("\nPercentages:\n\n"); printf("a %d%%; e %d%%; i %d%%; o %d%%; u %d%%; rest %d%%\n", pa, pe, pi, po, pu, pothers); }