Programming Examples

C program to calculate number of vowels separately in an entered string


Write a program to calculate number of vowels (a,e,i,o,u) separately in an entered string

Solution

#include <stdio.h>   
int main()
{
	char str[200];
	int a,e,i,o,u,x;
	a=e=i=o=u=0;
	printf("Enter any String : ");
	gets(str);
	for(x=0;str[x]!='\0';x++)
	{
		switch(str[x])
		{
			case 'a':
				a++;
			break;
			case 'e':
				e++;
			break;
			case 'i':
				i++;
			break;
			case 'o':
				o++;
			break;
			case 'u':
				u++;
			break;
		}
	}
	printf("\nNumber of vowels (a) : %d",a);	
	printf("\nNumber of vowels (e) : %d",e);
	printf("\nNumber of vowels (i) : %d",i);
	printf("\nNumber of vowels (o) : %d",o);
	printf("\nNumber of vowels (u) : %d",u);
	return 0;
}
Output

Enter any String : infomax computer academy


Number of vowels (a) : 3

Number of vowels (e) : 2

Number of vowels (i) : 1

Number of vowels (o) : 2

Number of vowels (u) : 1

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz