Advertisement
_fur

_fur | C Charisma Tubagus Setyobudhi

Dec 11th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int is_vowel(char c)
  5. {
  6.         int i;
  7.         int ret = 0;
  8.         char vow[10] = {'a', 'e', 'i', 'o', 'u',
  9.                         'A', 'E', 'I', 'O', 'U'};
  10.  
  11.         for (i = 0; i < 10; i++)
  12.                 if (vow[i] == c)
  13.                         ret = 1;
  14.         return ret;
  15. }
  16.  
  17. int is_alpha(char c)
  18. {
  19.        if ((c >= 'A' & c <= 'Z')
  20.          | (c >= 'a' & c <= 'z'))
  21.                 return 1;
  22.         return 0;
  23. }
  24.  
  25. int main(void)
  26. {
  27.         int i;
  28.         int cc = 0;
  29.         int cv = 0;
  30.         char *text = malloc(256);
  31.         char *p = text;
  32.  
  33.         printf("Input text: ");
  34.         fgets(text, 255, stdin);
  35.  
  36.         while(*p) {
  37.                 if(is_alpha(*p))
  38.                         if(is_vowel(*p))
  39.                                 cv++;
  40.                         else
  41.                                 cc++;
  42.                 p++;
  43.         }
  44.  
  45.         printf("Consonant : %d, Vowel : %d\n", cc, cv);
  46.         free(text);
  47.        
  48.         return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement