Wednesday

Write a program to count the number of vowels and consonants in a given text.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20];
int nv=0,nc=0,i;
printf("\nEnter any string");
gets(str);
strupr(str);
for(i=0;str[i]!='\0';i++)
{
if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U')
nv++;
else if(str[i]>='A' && str[i]<='Z')
nc++;
}
printf("\n No. of Vowels = %d ",nv);
printf("\n No. of Consonants = %d ",nc);
getch();
}

No comments:

Post a Comment

Rahul-Notes