Skip to main content

Program in C to display the number of vowels and consonants in a word

Program in C to display the number of vowels and consonants in a word.


#include <stdio.h>
#include <conio.h>
int main() {
    char str[100];
    int vowels = 0, consonants = 0;
    clrscr(); // Clear the screen
    printf("Enter a string: ");
    gets(str);
    for (int i = 0; str[i] != '\0'; i++) {
        if (isalpha(str[i])) {
            char ch = tolower(str[i]); // Convert to lowercase for case-insensitivity
            if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
                vowels++;
            else
                consonants++;
        }
    }
    printf("Number of vowels: %d\n", vowels);
    printf("Number of consonants: %d\n", consonants);
    getch(); // Wait for a key press
    return 0;
}

Popular posts from this blog