0
1.4kviews
Write a program to count number of vowels and consonants in a given sentence.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 10 M

Year: Dec 2016

1 Answer
0
3views
#include<stdio.h>
#include<conio.h>
main()
{
char a[50];
int i,vowels=0, consonants=0,space=0;
printf(“Enter a sentence:”);
gets(a);
for(i=0;a[i]!=’\0’;i++)
{
if(a[i]==’a’ || a[i]==’e’ || a[i]==’i’ || a[i]==’o’ || a[i]==’u’ || a[i]==’A’ || a[i]==’E’ || a[i]==’I’ || a[i]==’O’ || a[i]==’U’ )
    {
        vowels++;
}
else
{
    consonants++;
}
if(a[i]==’  ’)
{
space++;
}
}
consonants=consonants-space;
printf(“No of vowels in given sentence = %d”,vowels);
printf(“No of consonants in given sentence = %d”,consonants);
getch();
}

Output:
Enter a sentence: I love my India
No of vowels in given sentence = 6
No of consonants in given sentence = 6
Please log in to add an answer.