Answer to Question #167115 in C++ for Hanzala

Question #167115

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.


1
Expert's answer
2021-02-26T05:37:08-0500
#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]));
}

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