home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
array4.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-24
|
1KB
|
57 lines
// C++ program that passes arrays as arguments of functions
#include <iostream.h>
const int MAX = 10;
main()
{
int arr[MAX];
int n;
// declare prototypes of functions
int getMin(int a[MAX], int size);
int getMax(int a[], int size);
do { // obtain number of data points
cout << "Enter number of data points [2 to "
<< MAX << "] : ";
cin >> n;
cout << "\n";
} while (n < 2 || n > MAX);
// prompt user for data
for (int i = 0; i < n; i++) {
cout << "arr[" << i << "] : ";
cin >> arr[i];
}
cout << "Smallest value in array is "
<< getMin(arr, n) << "\n"
<< "Biggest value in array is "
<< getMax(arr, n) << "\n";
return 0;
}
int getMin(int a[MAX], int size)
{
int small = a[0];
// search for the smallest value in the
// remaining array elements
for (int i = 1; i < size; i++)
if (small > a[i])
small = a[i];
return small;
}
int getMax(int a[], int size)
{
int big = a[0];
// search for the bigest value in the
// remaining array elements
for (int i = 1; i < size; i++)
if (big < a[i])
big = a[i];
return big;
}