fork download
  1. //Q83. Count vowels and consonants in a string.
  2. #include <stdio.h>
  3. #include <ctype.h>
  4.  
  5. int main() {
  6. char str[100];
  7. int i, v=0, c=0;
  8. gets(str);
  9. for(i=0; str[i]!='\0'; i++) {
  10. char ch = tolower(str[i]);
  11. if(ch>='a' && ch<='z') {
  12. if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
  13. v++;
  14. else
  15. c++;
  16. }
  17. }
  18. printf("Vowels=%d Consonants=%d", v, c);
  19. }
  20.  
Success #stdin #stdout 0.01s 5324KB
stdin
hello
stdout
Vowels=2 Consonants=3