Advertisement
sharkar

C Program to Count the Number of Vowels, Consonants

Jun 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.53 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     // char data type with array
  6.     char string[120];
  7.  
  8.     // int data types
  9.     int i, vowels, consonants, digits, spaces;
  10.  
  11.     // Initial values to 0
  12.     vowels = consonants = digits = spaces = 0;
  13.  
  14.     printf("\t-: C Program to Count the Number of Vowels, Consonants:- \n\n");
  15.  
  16.     printf("Enter Any String: ");
  17.  
  18.     gets(string);
  19.  
  20.     // First check if any NULL Character given = \0
  21.     for(i=0; string[i] != '\0'; i++)
  22.     {
  23.         if(string[i]=='a' || string[i]== 'e' || string[i]== 'i' ||
  24.                 string[i] == 'o' || string[i]== 'u' || string[i]== 'A' ||
  25.                 string[i]== 'E' || string[i]== 'I' || string[i]== 'O' || string[i]== 'U')
  26.         {
  27.             // Post-increment
  28.             vowels++;
  29.         }
  30.  
  31.         else if((string[i] >= 'a' && string[i] <= 'z') || (string[i] >= 'A' && string[i] <= 'Z'))
  32.         {
  33.             // Post-increment
  34.             consonants++;
  35.         }
  36.  
  37.         else if(string[i] >= '0' && string[i] <= '9')
  38.         {
  39.             // Post-increment
  40.             digits++;
  41.         }
  42.  
  43.         else if (string[i] == ' ')
  44.         {
  45.             // Post-increment
  46.             spaces++;
  47.         }
  48.     }
  49.  
  50.     // Print the results
  51.  
  52.     printf("\n-: The Result is Below :-\n\n");
  53.  
  54.     printf("Total Vowel(s) Found : %d", vowels);
  55.  
  56.     printf("\n\nConsonant(s) Found : %d", consonants);
  57.  
  58.     printf("\n\nDigit(s) Found : %d", digits);
  59.  
  60.     printf("\n\nWhite Space(s) Found : %d", spaces);
  61.  
  62.     printf("\n");
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement