Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can somebody write a function in c++ that takes in an array of values and finds

ID: 3760789 • Letter: C

Question

Can somebody write a function in c++ that takes in an array of values and finds the minimum value of that array. The function should have two input parameters, the array of values, and the number of elements of the array. The function should be of type void but ouput the value and the location of the value in the array (its index). The minumum value of the array can appear in more than one location in the array. The function should output the value and its index everytime it appears in the array.

Explanation / Answer


#include<iostream>
using namespace std;
void minimum(int [],int); // function
int main()
{
  
   int array[]={1,2,3,4,5,6,1,1,4};
   minimum(array,9);
  
}

void minimum(int array[], int x)

{

int i;

int min=array[0];

for(i=0;i<x;i++)

{

if(array[i]<=min)

min=array[i];

}

for(i=0;i<x;i++)

{

if(array[i]==min)

{

cout<<"The Minimum value is "<<min<<" At index"<<i<<endl;

}

}

}