Write a C++ function to show all the INNOVATORS using one dimensional an•ay. An item value which is store in array is Innovator if it is greater than all the items to its left side. And the left most item is always an Innovator. For example, in the array {11, 21, 19, 33, 79, 41}, Innovator are 79,
21 and 11.
#include <iostream>
using namespace std;
void PrintInnovators(int array[], int n) {
int curInnovator = array[0];
cout << "Innovators are:" << endl;
cout << curInnovator;
for (int i=1; i<n; i++) {
if (array[i] > curInnovator) {
curInnovator = array[i];
cout << " " << curInnovator;
}
}
cout << endl;
}
int main() {
int array[] {11, 21, 19, 33, 79, 41};
PrintInnovators(array, sizeof(array)/sizeof(array[0]));
}
Comments
Leave a comment