Write a function that finds the smallest element in an array of double values using the following header:
double min(double list[], int size)
Write a test program that prompts the user to enter 10 numbers, invokes this function, and displays the minimum value. Here is a sample run of the program:
Enter ten numbers: 1.9 2.5 3.7 2 1.5 6 3 4 5 2 <enter>
The minimum number is 1.5
1
Expert's answer
2016-11-11T05:41:09-0500
#include <iostream> #include <conio.h> using namespace std;
double min(double list[], int size) { double result = list[0]; for(int i = 1; i < size; i++) if(result > list[i]) result = list[i]; return result; }
int main() { double arr[10]; cout << "Enter ten numbers: "; for(int i = 0; i < 10; i++) cin >> arr[i]; if(cin.fail()) { cout << "Wrong input!"; _getch(); return 1; } cout << "The minimum number is " << min(arr, 10);
Comments
Leave a comment