In: Computer Science
In C++ please.
7. Provided that c1, c2 and c3 are of appropriate ranges. Use transform() algorithm so that it copies the larger of the corresponding elements from c1 and c2 to c3. That is, if c1 = {1, 2, 3, 4, 5} and c2 = {5, 4, 3, 2, 1} then c3 should become c3={5, 4, 3, 4, 5}
7). ANSWER :
GIVENTHAT :
C++ PROGRAM :
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int compare(int a, int b){
if(a>b){
return a;
}
else{
return b;
}
}
int main()
{
int c1[]={1,2,3,4,5};
int c2[]={5,4,3,2,1};
int n=sizeof(c1)/sizeof(c1[0]); //to get number of elements in
array c1
int c3[n];
//transform(Iteretor inputBegin1,Iteretor inputEnd1,Iteretor
inputBegin2,Iteretor OutputBeign,binary_opertion)
transform(c1,c1+n,c2,c3,compare);
for(int i=0;i<n;i++){
std::cout << c3[i] << " ";
}
return 0;
}