Write a function named buildArray that builds an array by appending a given number of random two-digit integers (10-99). It should accept two parameters — the first parameter is the array, and the second is an integer for how many random values to add, which should be input by the user.

Respuesta :

Answer:

The function in C++ is as follows:

void buildArray(int arr[], int n){

   srand(time(NULL));

   for(int i = 0;i<n;i++){

       arr[i] = rand() % 99 + 10;    }

   for(int i = 0;i<n;i++){

       cout<<arr[i]<<" ";

   }

}

Explanation:

This defines the function

void buildArray(int arr[], int n){

This klets the program generate different random numbers

   srand(time(NULL));

This iterates from 0 to n - 1 (n represents the length of the array)

   for(int i = 0;i<n;i++){

This generates random 2 digit integer into the array

       arr[i] = rand() % 99 + 10;    }

This iterates through the array and print the array elements

   for(int i = 0;i<n;i++){

       cout<<arr[i]<<" ";

   }

}

See attachment for complete program that includes the main

Ver imagen MrRoyal
ACCESS MORE