Question: . Complete the given C++ program (prob1.cpp) to read an array, print the array, find and print the smallest positive number. Basically, complete the two

. Complete the given C++ program (prob1.cpp) to read an array, print the array, find and print the smallest positive number. Basically, complete the two functions printArray and getElement.

printArray must print the values in the array in order with a space and comma between each one and an endline after the last value.

getElement must return the smallest positive number. If there are no positive numbers in the array it must return 0. Test these cases.

A sample run is given below:

Enter number of integers : 5

Enter 5 integers: 4 6 8 -12 -9

Contents of array: 4, 6, 8, -12, -9

Output of getElement: 4

A second test case:

Enter number of integers : 5

Enter 5 integers: -1 -2 -3 -4 -5

Contents of array : -1 -2 -3 -4 -5

Output of getElement: 0

code:

#include

#include

using namespace std;

// Implement printArray here

void printArray(int myarray[], int n)

{

}

// Implement getElement here

int getElement(int myarray[], int n)

{

}

// DO NOT CHANGE MAIN FUNCTION BELOW

int main() {

int myarray[100];

cout << "Enter number of integers : ";

int n;

cin >> n;

cout << " Enter " << n << " integers: " << endl;

for (int i = 0; i < n; i++)

cin >> myarray[i];

cout << "Contents of array : ";

printArray(myarray, n);

cout << "Output of getElement: " << getElement(myarray, n) << endl;

system("pause"); // comment/uncomment if needed

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!