C Program to Count the Number of Vowels & Consonants

In this post we count the number of vowels and consonants occurred in the String.


Implementation:


#include <stdio.h>
int main() 
{
    char line[150]
    int vowels, consonant;
    vowels = consonant = 0;
    printf("Enter a string: ");
    scanf("%s",line);
    for (int i = 0; line[i] != '\0'; i++) 
    {
        if(line[i] == 'a' || line[i] == 'e' || line[i] == 'i' ||
           line[i] == 'o' || line[i] == 'u' || line[i] == 'A' ||        
           line[i] == 'E' || line[i] == 'I' || line[i] == 'O' || 
           line[i] == 'U')
        {
            vowels++;
        }
        else if ((line[i] >= 'a' && line[i] <= 'z') ||
                 (line[i] >= 'A' && line[i] <= 'Z'))
         {
             consonant++;
         }
         printf("Vowels: %d", vowels);
         printf("\n Consonants: %d", consonant);
         return 0;
}
Output:
Enter a string: ProgrammersDoor
Vowels: 5
Consonants: 10

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Follow Programmers Door for more.

#programming #blog #count #c

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door