1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
void find_smallest( int a[], int n );
void find_largest( int a[], int n );
int main()
{
int a[] = { 14, 73, 81, 9, 10, 12, 5, 11, 100, 94 };
int n = 10; // array size
find_smallest( a, n );
find_largest( a, n );
return 0;
} // main
void find_smallest( int a[], int n )
{
int smallest = a[0];
for ( int i = 0; i < n; ++i )
{
if ( a[i] < smallest )
{
smallest = a[i];
} // if
} // for
std::cout << "smallest=" << smallest << "\n";
} // find_smallest
void find_largest( int a[], int n )
{
int largest = a[0];
for ( int i = 0; i < n; ++i )
{
if ( a[i] > largest )
{
largest = a[i];
} // if
} // for
std::cout << "largest=" << largest << "\n";
} // find_largest
|