Program to count the number of vowels and consonants in a string.


C File =>



/* Write a C program to count the number of vowels and consonants in a string. */


#include<stdio.h>
#include<string.h>
int main()
{
       char s[50];
       char ch;
       int i,vcnt=0,cnt=0;
        printf("\n Enter String : ");
        scanf("%[^\n]s",s);
 for(i=0;i<strlen(s);i++)
{
     if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
        vcnt++;
    else
        cnt++;
}
printf("\n Count of vowels = %d \n Count of consonants = %d",vcnt,cnt);
return 0;
}


Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.