fork download
  1. #include <stdio.h>
  2. int main() {
  3. char str[100];
  4. int vowels = 0, consonants = 0, others = 0, digits=0;
  5. int n,m;
  6. printf("String Size: ");
  7. scanf("%d", &n);
  8. printf("Enter String : ");
  9. for(int i=0; i<n; i++){
  10. scanf(" %c", &str[i]);
  11. }
  12.  
  13. for (int i = 0; i<n; i++) {
  14. char ch = tolower(str[i]);
  15. if ((ch >= 'a' && ch <= 'z')) {
  16. if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
  17. vowels++;
  18. }
  19. else {
  20. consonants++;
  21. }
  22. }
  23. else if (ch >= '0' && ch <= '9') {
  24. digits++;
  25. }
  26. else {
  27. others++;
  28. }
  29. }
  30.  
  31. printf("Vowels: %d\n", vowels);
  32. printf("Consonants: %d\n", consonants);
  33. printf("Digits: %d\n", digits);
  34. printf("Other characters: %d\n", others);
  35. }
Success #stdin #stdout 0.01s 5284KB
stdin
10
abcdADF124
stdout
String Size: Enter String : Vowels: 2
Consonants: 5
Digits: 3
Other characters: 0