Write a program to create a dynamic array of user defined size. Array should be character type. Write a function RemoveVowels() that should remove all the vowels in the array. All array operations should be done using pointers.
SOLUTION CODE FOR THE ABOVE QUESTION
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
void RemoveVowels(char str[], int n)
{
vector<char> vowels = {'a', 'e', 'i', 'o', 'u','A', 'E', 'I', 'O', 'U'};
for (int i = 0; i < n(); i++)
{
if (find(vowels.begin(), vowels.end(),
str[i]) != vowels.end())
{
str[i] = str.replace(i, 1, "");
i -= 1;
}
}
}
int main(){
cout<<"Enter the size of the array:\n";
int n;
cin>>n;
char letters[n];
cout<<"Enter the string\n";
cin>>letters;
RemoveVowels(letters,n);
cout<<letters<<endl;
}
Comments
Leave a comment