Count Vowels in a String in C | AskTheCode

Asked by: Eman Hmood | Count total number of vowels in a string in C

Here is a C program that counts the total number of vowels in a given string.


#include <stdio.h>

int main()

{

char str[100];

int c = 0, count = 0;

printf("Enter the string: ");

gets(str);


while (str[c] != '\0') {

if (str[c] == 'a' || str[c] == 'A' || str[c] == 'e' || str[c] == 'E' || str[c] == 'i' || str[c] == 'I' || str[c] =='o' || str[c]=='O' || str[c] == 'u' || str[c] == 'U')

count++;

c++;

}


printf("Number of vowels in the string: %d", count);


return 0;

}


24 views0 comments

Recent Posts

See All

"Believe you can and you're halfway there"