Table of Contents
C program to count vowels and consonants in a string
Vowels are a,e,i,o,u and rest of the alphabets are called consonants.
This C program will count vowels, consonants, spaces and special character.
#include<stdio.h>
//itvoyagers.in
int main()
{
char msg[]="ITVoyagers - Let's sail across an ocean of IT";
int i, v=0, c=0, s=0, sc=0, l=sizeof(msg)/sizeof(char);
for(i=0; i<l-1; i++)
{
if(msg[i]=='a' || msg[i]=='e' || msg[i]=='i' || msg[i]=='o' || msg[i]=='u' ||
msg[i]=='A' || msg[i]=='E' || msg[i]=='I' || msg[i]=='O' || msg[i]=='U')
{
v++;
}
//itvoyagers.in
else if((msg[i]>='a' && msg[i]<='z') || (msg[i]>='A' && msg[i]<='Z'))
{
c++;
}
else if(msg[i]==' ')
{
s++;
}
else
{
sc++;
}
//itvoyagers.in
}
printf("nCount of Vowels : %d",v);
printf("nCount of consonant : %d",c);
printf("nCount of Spaces : %d",s);
printf("nCount of Special characters : %d",sc);
}
Output :
Count of Vowels : 15
Count of consonant : 20
Count of Spaces : 8
Count of Special characters : 2
PRACTICALS/PRACTICE PROGRAM IN C
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on Operator |
Easy Quiz on Operators in C part 1 |
Easy quiz on operators in C part 2 |
Easy quiz on operators in C part 3 |
Quizzes on Loops |
Easy quiz on loops in C part 1 |
Easy quiz on loops in C part 2 |
Easy quiz on loops in C part 3 |
Quizzes on Decision Making Statement |
Easy Quiz On Decision Making Statements Part 1 |
Easy Quiz On Decision Making Statements Part 2 |
Quizzes on String |
Easy quiz on String in C programming part 1 |
Quizzes on Array |
Easy quiz on Array in C programming – part 1 |
5 – Best Java program to convert decimal to binary |
New Quizzes Coming soon.. |
We are aiming to explain all concepts of C in easiest terms as possible.

ITVoyagers
Author