Advertisement
Md_hosen_zisad

count vowel,con,space,digit from a string

Oct 10th, 2017
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. char line[150];
  6. int i, vowels, consonants, digits, spaces;
  7.  
  8. vowels = consonants = digits = spaces = 0;
  9.  
  10. printf("Enter a line of string: ");
  11. gets(line);
  12. for(i=0; line[i]!='\0'; ++i)
  13. {
  14. if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
  15. line[i]=='o' || line[i]=='u' || line[i]=='A' ||
  16. line[i]=='E' || line[i]=='I' || line[i]=='O' ||
  17. line[i]=='U')
  18. {
  19. ++vowels;
  20. }
  21. else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
  22. {
  23. ++consonants;
  24. }
  25. else if(line[i]>='0' && line[i]<='9')
  26. {
  27. ++digits;
  28. }
  29. else if (line[i]==' ')
  30. {
  31. ++spaces;
  32. }
  33. }
  34.  
  35. printf("Vowels: %d",vowels);
  36. printf("\nConsonants: %d",consonants);
  37. printf("\nDigits: %d",digits);
  38. printf("\nWhite spaces: %d", spaces);
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement