fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5. char input[101];
  6. int vowelCount[5] = {0};
  7. char vowels[5] = {'a', 'e', 'i', 'o', 'u'};
  8.  
  9. do {
  10. printf("Enter a string (1 to 99 characters): ");
  11. scanf("%100s", input);
  12. } while(strlen(input) == 0 || strlen(input) >= 100);
  13.  
  14. for (int i = 0; input[i] != '\0'; i++) {
  15. switch(input[i]) {
  16. case 'a': case 'A':
  17. vowelCount[0]++;
  18. break;
  19. case 'e': case 'E':
  20. vowelCount[1]++;
  21. break;
  22. case 'i': case 'I':
  23. vowelCount[2]++;
  24. break;
  25. case 'o': case 'O':
  26. vowelCount[3]++;
  27. break;
  28. case 'u': case 'U':
  29. vowelCount[4]++;
  30. break;
  31. }
  32. }
  33.  
  34. printf("Original counts:\n");
  35. for (int i = 0; i < 5; i++) {
  36. printf("Vowel '%c' : %d\n", vowels[i], vowelCount[i]);
  37. }
  38.  
  39. int i = 0;
  40. while (i < 4) {
  41. if (vowelCount[i] < vowelCount[i + 1]) {
  42. int temp = vowelCount[i];
  43. vowelCount[i] = vowelCount[i + 1];
  44. vowelCount[i + 1] = temp;
  45.  
  46. char tempChar = vowels[i];
  47. vowels[i] = vowels[i + 1];
  48. vowels[i + 1] = tempChar;
  49.  
  50. i = 0;
  51. } else {
  52. i++;
  53. }
  54. }
  55.  
  56. printf("Sorted:\n");
  57. for (int i = 0; i < 5; i++) {
  58. printf("%c: %d\n", vowels[i], vowelCount[i]);
  59. }
  60.  
  61. return 0;
  62. }
  63.  
Success #stdin #stdout 0.01s 5288KB
stdin
oiuaeaeoiuaaoooiiiieeeeuuuuuu
stdout
Enter a string (1 to 99 characters): Original counts:
Vowel 'a' : 4
Vowel 'e' : 6
Vowel 'i' : 6
Vowel 'o' : 5
Vowel 'u' : 8
Sorted:
u: 8
e: 6
i: 6
o: 5
a: 4