Question #100735

Write a value returning function smaller to determine the smallest number from a set of numbers.Ise this function to determine the smallest number from a set of 10 number

Expert's answer

/*

The program MinimumOfTen displays the minimum number entered.

User enters 10 numbers from console.

*/

#include <iostream>

using namespace std;

/*

An array arr of double is sent to the function double minNumber(double*, int).

And amount of numbers in array arr is sent to the function double minNumber(double*, int).

The value of the double minInArr variable is returned.

*/

double minNumber(double*, int);


int main()

{

double arr[10];

cout << "Enter ten numbers: ";

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

{

cin >> arr[i];

}

cout << "Minimum number: " << minNumber(arr, 10);

}


double minNumber(double* arr, int num)

{

double minInArr = arr[0];

for (int i = 1; i < num; i++)

{

if (minInArr > arr[i])

{

minInArr = arr[i];

}

}

return minInArr;

}
LATEST TUTORIALS
APPROVED BY CLIENTS