Write a C program to find the number of vowels and consonants in a given string.

#include<stdio.h>
#include<string.h>
main()
{
    char str[100];
    int i,v=0,c=0;

    printf("\nEnter a string=");
    scanf("%s",str);
    for(i=0;i<strlen(str);i++)
    {
        if((str[i]>='A' && str[i]<='Z')||(str[i]>='a' && str[i]<='z'))
        {
            if(str[i]=='a' ||str[i]=='A' ||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||str[i]=='u'||str[i]=='U')
                v++;
            else
                c++;
        }
    }

    printf("\nThe number of vowels=%d, Number of consonants=%d",v,c);
}

No comments:

Post a Comment