Reverse Vowels

Reverse vowels in a given string

         Given a string,task is to reverse the vowels of the string.
Sample Input 1:
jobat update
Sample Output 1:
jebat updato
Sample Input 2:
hello world
Sample Output 2:
hollo werld

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
#include<string.h>
int main()
{
    char a[20],b[20],t[20];
    int j=0,l,k,i;
    printf("Enter the string  ");
    gets(a);
    l=strlen(a);
    for(i=0;i<l;i++)
    {
        if((a[i]=='a')||(a[i]=='i')||(a[i]=='o')||(a[i]=='u')||(a[i]=='e'))
        {
            b[j]=a[i]; //vowels stored in another array
            j++;
        }
    }
    k=strlen(b);
    j=0;
    for(i=l-1;i>=0;i--)
    {
        if((a[i]=='a')||(a[i]=='i')||(a[i]=='o')||(a[i]=='u')||(a[i]=='e'))
        {
            a[i]=b[j];
            j++;
        }
    }
    printf("%s",a);
}

OUTPUT




0 comments