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.
#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);
}
Comments
Leave a comment