4. Write a C program to read input 10 characters from the user and print the count of vowels and consonants in the output.
C PROGRAM:-
#include <stdio.h>
int main() {
char line[11];
int vowels, consonant;
vowels = consonant = 0;
printf("Enter a line of string with character 10: ");
fgets(line, sizeof(line), stdin);
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("\nConsonants: %d", consonant);
return 0;
}
Step by step
Solved in 2 steps with 1 images