Tuesday, 20 October 2015

C program to print total number of vowels in a string

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

No comments:

Post a Comment