Westonci.ca offers quick and accurate answers to your questions. Join our community and get the insights you need today. Discover in-depth solutions to your questions from a wide range of experts on our user-friendly Q&A platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

Write a value-returning function that receives an array of integer values and the array size as parameters and returns a count of the number of elements that are less than 60.

Sagot :

Answer:

The c++ function for reversing an array is given. The function is declared void since it returns no value.

void reverse( int arr[], int len )

{

  int temp[len];

  for( int k = 0; k < len; k++ )

  {

      temp[k] = arr[k];

  }

  for( int k = 0, j = len-1; k < len, j>= 0; k++, j-- )

  {

          arr[k] = temp[j];

   }

}

Explanation:

The reverse function uses another array to reverse the elements of the original array.

An integer array is declared, temp[len], having the same length as the input array.

int temp[len];

To begin with, the elements of the input array are copied in the temp array.

for(int k = 0; k < len; k++ )

{

      temp[k] = arr[k];

}

Next, the elements of the input array are given new value.

The temp array, in reverse order, is copied into the input array.

for( int k = 0, j = len-1; k < len, j>= 0; k++, j-- )

{

          arr[k] = temp[j];

}

The above for loop makes use of two variables simultaneously.

While the array, arr is proceeding from first element to the next, the array temp begins with the last element and goes down to the previous element.

Now, the input array, arr, contains the elements in reverse order.

The complete program is given.

#include <iostream>

using namespace std;  

void reverse( int arr[], int len );

void reverse( int arr[], int len )

{

  int temp[len];

 

  for(int k = 0; k < len; k++ )

  {

      temp[k] = arr[k];

  }

 

  for( int k = 0, j = len-1; k < len, j>= 0; k++, j-- )

  {

          arr[k] = temp[j];

  }

 

}

int main()  

{

  int len = 5;    

  int arri[len];    

  for( int l = 0; l < len; l++ )

  {

      arri[l] = l;

  }

 

  reverse( arri, len );    

  return 0;

}

Thanks for using our service. We aim to provide the most accurate answers for all your queries. Visit us again for more insights. Thank you for choosing our platform. We're dedicated to providing the best answers for all your questions. Visit us again. Thank you for choosing Westonci.ca as your information source. We look forward to your next visit.