Header Ad

C Program to find occurrences of vowels, consonants, words, spaces, and special characters in the given sentence

In this tutorial, we are going to write a C Program to find the number of occurrences of vowels, consonants, words, spaces, and special characters in the given sentence in C Programming with practical program code and step-by-step full complete explanation.

C Program to find occurrences of vowels, consonants, words, spaces, and special characters in the given sentence


C Program code.

 
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

void main()
{
	char s[100];
	int vow=0,cons=0,spc=0,punc=0,l,i;

	clrscr();

	printf("Enter the statement\n");

	gets(s);
	l=strlen(s);

	for(i=0;i<l;i++)
	{
		if(isalpha(s[i]))
		{
			if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')
			{
				vow++;
			}
			else
			{
				cons++;
			}
		}
		if(isspace(s[i]))
		{
			spc++;
		}

		if(ispunct(s[i]))
		{
		punc++;
		}	
	}

	printf("\nNumber of words=%d",spc+1);
	printf("\nNumber of vowels=%d",vow);
	printf("\nNumber of consonants=%d",cons);
	printf("\nNumber of space=%d",spc);
	printf("\nNumber of special characters=%d",punc);

	getch();
}


Output

 
Enter the statement
*Nothing is impossible in the world.
Number of words=6
Number of vowels=10
Number of consonants=19
Number of space=5
Number of special characters=1


Post a Comment

0 Comments