(Print an Array) Write a recursive function printArray that takes an array, a starting sub- script and an ending subscript as arguments and returns nothing. The function should stop process- ing and return when the starting subscript equals the ending subscript.

What will be an ideal response?


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

void printArray( const int [], int, int );

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

srand( time( 0 ) );

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

cout << "Array values printed in main:\n";

for ( int j = 0; j < SIZE; j++ ) // print array elements
cout << setw( 5 ) << array[ j ];

cout << "\n\nArray values printed in printArray:\n";
printArray( array, 0, SIZE - 1 );
cout << endl;
} // end main

void printArray( const int array[], int low, int high )
{
// print first element of array passed
cout << setw( 5 ) << array[ low ];

// return if array only has 1 element
if ( low == high )
return;
else // recursively call printArray with new subarray as argument
printArray( array, low + 1, high );
} // end function printArray
```
Array values printed in main:
465 117 93 285 373 172 472 439 455 31
Array values printed in printArray:
465 117 93 285 373 172 472 439 455 31

Computer Science & Information Technology

You might also like to view...

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

1. It is legal to assign C-string variables. 2. The = sign used to give a variable an initial value in a definition, ``` char ch = ‘A’; ``` is different from the = sign in an assignment. ``` ch = ‘B’; ``` 3. The C-string library functions use the null terminator to decide when to stop processing. 4. The C-string library functions are safe and require no special care. 5. The C-string library function strcmp compares two strings for equal length.

Computer Science & Information Technology

________ is where Windows 8.1 monitors your system for various maintenance and security settings and recommends action when necessary

Fill in the blank(s) with correct word

Computer Science & Information Technology

The MATCH function Match_type argument specifies the item for which you are searching

Indicate whether the statement is true or false.

Computer Science & Information Technology

You always must qualify field names, even if there is no possibility of confusion.

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

Computer Science & Information Technology