Count Vowels in a String in C | AskTheCode

Updated: Mar 10

C++ program to count total number of vowels in a string in C | CPP programming | ATC

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;
}

31 views0 comments

Recent Posts

See All