In this program, you will learn to count all vowels in a sentence (entered by the user).
Following example shows the output of the program:
1 2 |
Input: Hello C Programming Output: 5 (vowels) |
Example: Program Count Vowels in Sentence
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include<stdio.h> #include<string.h> int main() { int i,vowelcount = 0; char str[100]; printf("Enter a sentence or string: \n"); gets(str); for(i = 0; i < strlen(str); i++) { if(str[i]=='A'||str[i]=='a'||str[i]=='e'||str[i]=='E' ||str[i]=='I' ||str[i]=='i'||str[i]=='O'||str[i]=='o' ||str[i]=='U'||str[i]=='u') { vowelcount++; } } printf("%d\n",vowelcount); //exit status return 0; } |
1 2 3 |
Enter a sentence or string: i am a programmer 6 |