C Program to Count Vowels, Consonants and Spaces in a string

C Program to count vowels, consonants and spaces in a string in C Programming Language ?

This C Program to Count Vowels, Consonants and Spaces in a string.
In this C Program the Sentence is Entered by the User and the C Program then Count Vowels, Consonants and Spaces in a String.

To Find:
  1. Total number of vowels entered.
  2. Total number of consonants entered.
  3. Total number of spaces entered.

Solution:

  1. #include<stdio.h>
  2. main()
  3. {
  4. int i,cons=0,vow=0,sp=0;
  5. char a[100];
  6. printf("Enter the sentence\n");
  7. gets(a);
  8. for(i=0;a[i]!='\0';i++)
  9. {
  10. if(a[i]=='a'||a[i]=='A')
  11. vow=vow+1;
  12. else if(a[i]=='e'||a[i]=='E')
  13. vow=vow+1;
  14. else if(a[i]=='i'||a[i]=='I')
  15. vow=vow+1;
  16. else if(a[i]=='o'||a[i]=='O')
  17. vow=vow+1;
  18. else if(a[i]=='u'||a[i]=='U')
  19. vow=vow+1;
  20. else if(a[i]==' ')
  21. sp=sp+1;
  22. else
  23. cons=cons+1;
  24. }
  25. printf("Total number of vowels entered = %d\n",vow);
  26. printf("Total number of consonants entered = %d\n",cons);
  27. printf("Total number of spaces entered = %d\n",sp);
  28. }


Learn More :