C program to count no. of vowels and consonants in a string

PROGRAM:

#include<stdio.h>
int main()
{
    char str[50];
    int i=0,vowel=0,cons=0;
    printf("Enter a string\n");
    scanf("%s",str);
    printf("Entered string is %s\n",str);
    while(str[i]!='\0')
    {
        if((str[i]>='A' && str[i]<='Z')||(str[i]>='a' && str[i]<='z'))
        {
            if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='0'||str[i]=='U')
            {
                vowel++;
            }
            else
            {
                cons++;
            }
        }
        i++;
    }
    printf("No. of vowels=%d\nNo. of consonants=%d\n",vowel,cons);
    return 0;
}


OUTPUT:

Enter a string
IndiaIsGreat
Entered string is IndiaIsGreat
No. of vowels=6
No. of consonants=6

Popular Posts