(Find the Minimum Value in an Array) Write a recursive function recursiveMinimum that takes an integer array, a starting subscript and an ending subscript as arguments, and returns the smallest element of the array. The function should stop processing and return when the starting sub- script equals the ending subscript.

What will be an ideal response?


```
#include
#include
#include
#include
using namespace std;

const int MAXRANGE = 1000;
int recursiveMinimum( const int [], int, int );

int main()
{
const int SIZE = 10;
int array[ SIZE ];
int smallest;

srand( time( 0 ) );

// initialize elements of array to random numbers
for ( int loop = 0; loop < SIZE; loop++ )
array[ loop ] = 1 + rand() % MAXRANGE;

// display array
cout << "Array members are:\n";

for ( int k = 0; k < SIZE; k++ )
cout << setw( 5 ) << array[ k ];

// find and display smallest array element
cout << '\n';
smallest = recursiveMinimum( array, 0, SIZE - 1 );
cout << "\nSmallest element is: " << smallest << endl;
} // end main

// function to recursively find minimum array element
int recursiveMinimum( const int array[], int low, int high )
{
static int smallest = MAXRANGE;

// if first element of array is smallest so far
// set smallest equal to that element
if ( array[ low ] < smallest )
smallest = array[ low ];

// if only one element in array, return smallest
// else recursively call recursiveMinimum with new subarray
return low == high ?
smallest : recursiveMinimum( array, low + 1, high );
} // end function recursiveMinimum
```
Array members are:
309 893 72 270 109 830 338 487 240 505
Smallest element is: 72

Computer Science & Information Technology

You might also like to view...

Rewrite bundle (page 451) so the script it creates takes an optional list of filenames as arguments. If one or more filenames are given on the command line, only those files should be re-created; otherwise, all files in the shell archive should be re-created. For example, suppose all files with the file- name extension .c are bundled into an archive named srcshell, and you want to unbundle just the files test1.c and test2.c. The following command will unbundle just these two files:

$ bash srcshell test1.c test2.c

Computer Science & Information Technology

To link to another Web site, the href attribute must contain the ftp:// protocol.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

________ profiles require a network server for implementation

a. Local and temporary b. Roaming and temporary c. Mandatory and roaming d. Roaming and local

Computer Science & Information Technology

A database is divided into separate tables.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology