New Android apps UniqueKey

Sunday 22 February 2015

Find no. of vowels , consonants , digits and white spaces in a string.


#include<stdio.h>

main()
{
    char str[150];
    int i,v,c,ch,d,s,o;
    
    o=v=c=ch=d=s=0;
    
    printf("Enter a string:\n");
    gets(str);
    
    for(i=0;str[i]!='\0';i++)
    {
        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]=='O' || str[i]=='U')
            ++v;
        else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z'))
            ++c;
        else if(str[i]>='0'&&c<='9')
            ++d;
        else if (str[i]==' ')
            ++s;
    }
    printf("Vowels: %d",v);
    printf("\nConsonants: %d",c);
    printf("\nDigits: %d",d);
    printf("\nWhite spaces: %d",s);
}

No comments:

Post a Comment