Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

Swap Every Two Vowels

Swap Every Two Vowels 

 The program must accept a string S as the input. The program must swap every two vowels in the string S. Then the program must print the revised string S as the output. If the number of vowels is odd, then the last vowel will remain the same as there is no pair to swap.

Note: The string S always contains at least two vowels.


Input Format:

The first line contains S.


Output Format:

The first line contains the revised string S.


Example Input/Output 1:

Input:

environment


Output:

inverenmont


Explanation:

There are four vowels in the given string "environment".

After swapping the vowels e and i, the string environment becomes inveronment.

After swapping the vowels o and e, the string inveronment becomes inverenmont.

Hence the output is inverenmont.


Example Input/Output 2:

Input:

TOUCHPAD


Output:

TUOCHPAD


C Program:

#include<stdio.h>

#include<stdlib.h>

int isVowel(char ch)

{

char f=tolower(ch);

if(f=='a' || f=='e' ||f=='i'||f=='o' ||f=='u')

{

return 1;

}

return 0;

}


int main()

{ char s[1001];

  scanf("%s",s);

  int len=strlen(s);

  for(int i=0;i<len;i++)

     {if(isVowel(s[i]))

        {

        for(int j=i+1;j<len;j++)

           {if(isVowel(s[j]))

              {char d=s[i];

                s[i]=s[j];

                s[j]=d;

                i=j;

                break;

               }

            }

        }

     }

printf("%s",s);

return 0;

}

Post a Comment

Previous Post Next Post