C Program to count vowels, consonants and spaces in a string in C Programming Language ?
This C Program to Count Vowels, Consonants and Spaces in a string.
In this C Program the Sentence is Entered by the User and the C Program then Count Vowels, Consonants and Spaces in a String.
To Find:
- Total number of vowels entered.
- Total number of consonants entered.
- Total number of spaces entered.
Solution:
- #include<stdio.h>
- main()
- {
- int i,cons=0,vow=0,sp=0;
- char a[100];
- printf("Enter the sentence\n");
- gets(a);
- for(i=0;a[i]!='\0';i++)
- {
- if(a[i]=='a'||a[i]=='A')
- vow=vow+1;
- else if(a[i]=='e'||a[i]=='E')
- vow=vow+1;
- else if(a[i]=='i'||a[i]=='I')
- vow=vow+1;
- else if(a[i]=='o'||a[i]=='O')
- vow=vow+1;
- else if(a[i]=='u'||a[i]=='U')
- vow=vow+1;
- else if(a[i]==' ')
- sp=sp+1;
- else
- cons=cons+1;
- }
- printf("Total number of vowels entered = %d\n",vow);
- printf("Total number of consonants entered = %d\n",cons);
- printf("Total number of spaces entered = %d\n",sp);
- }