Initialize a character array of size 30. Your program should take a two character value and replacement from user. After taking input replace all occurrences of character value with character replacement.

#include<iostream>
using namespace std;
int main()
{
	const int size = 30;
	char val1, val2, rep1, rep2;
	char arr[size] = "aaalllbbbuuuiiioooppp";
	cout << "Enter character you find : ";
	cin >> val1;
	cin >> val2;
	cout << "Enter character to change : ";
	cin >> rep1;
	cin >> rep2;
	for (int i = 0; i<size; i++)
	{
		if (val1 == arr[i])
		{
			arr[i] = rep1;
		}
		else if (val2 == arr[i])
		{
			arr[i] = rep2;
		}
		cout << arr[i];
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *