Tuesday, 20 October 2015

C program to find the frequency of vowels in a string

#include<stdio.h>
#include<conio.h>
void main()
{
char name[20],ch=0;
int j=0,a=0,e=0,i=0,o=0,u=0,sum=0;
clrscr();
printf("\n enter a name :");
ch=getchar();
    while(ch!='.')
    {
        name[j]=ch;
        j++;
        ch=getchar();
    }
    name[j]='\0';
    printf("\n your name is :");
    j=0;
        while(name[j]!='\0')
        {
            ch=name[j];
                if(ch=='a'||ch=='A')
                        a=a++;
                if(ch=='e'||ch=='E')
                        e=e++;
                if(ch=='i'||ch=='I')
                        i=i++;
                if(ch=='o'||ch=='O')
                        o=o++;
                if(ch=='u'||ch=='U')
                        u=u++;
                sum=a+e+i+o+u;
                putchar(ch);
                j++;
        }
printf("\n no. of occurences of a is=%d",a);
printf("\n no. of occurences of e is=%d",e);
printf("\n no. of occurences of i is=%d",i);
printf("\n no. of occurences of o is=%d",o);
printf("\n no. of occurences of u is=%d",u);
printf("\n total no. of vowels is=%d",sum);
getch();
}

No comments:

Post a Comment