Answer to Question #256247 in C++ for khangphanana

Question #256247

Write a function that replaces the elements of an integer sequence whose value a is the value of b. Write a main program that uses that function and displays the resulting sequence of numbers on the screen.


1
Expert's answer
2021-10-25T03:02:07-0400
#include<iostream>
using namespace std;
void replace(int arr[], int a, int b,int n){


	for(int i=0; i<n; i++){
		if(arr[i]==a){
			arr[i]=b;
		}
	}
	
	for(int i=0; i<n; i++){
		cout<<arr[i]<<" ";
	}
}


int main(){
	int sequence[]={1, 2, 5, 2, 6, 7, 8, 12};
	replace(sequence, 2,9,8);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS