1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gekata [30.6K]
3 years ago
15

Write the definition of a function reverse, whose first parameter is an array of integers and whose second parameter is the numb

er of elements in the array. The function reverses the elements of the array. The function does not return a value.
Computers and Technology
1 answer:
GrogVix [38]3 years ago
8 0

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;

}

You might be interested in
As defined by the National Institute of Standards and Technology​ (NIST), "________ is a model for enabling​ ubiquitous, conveni
hram777 [196]

Answer:

Cloud Computing

Explanation:

It is certainly a model for enabling ubiquitous, on-demand and convenient network access for using a shared pool of configurable computing resources, and that can rapidly be provisioned as well as released with the least managing effort or the interaction of the service provider. And such a facility is only being provided by the cloud computing currently. And hence the Cloud computing, the right answer.

5 0
3 years ago
Please help me with this question. I don’t get it
Lelechka [254]
A - they all use microprocessors to compute and store data.
3 0
3 years ago
Read 2 more answers
How many different integers can be represented with a 4-digit number in base 13?
AnnyKZ [126]
That would be 13^4, or 13*13*13*13 = 28561
6 0
3 years ago
List any two different between primary memory and secondary memory.​
nikitadnepr [17]

Answer:

Primary memory is directly accessible by Processor/CPU. Secondary memory is not directly accessible by the CPU. ... The memory devices used for primary memory are semiconductor memories. The secondary memory devices are magnetic and optical memories

3 0
3 years ago
Read 2 more answers
If you paste a word document text into an excel spreadsheet, the paste optio allow you to keep source formatting or
castortr0y [4]
I think the answer is c
6 0
3 years ago
Other questions:
  • Jerry suspects that information about his internet usage was sent to external websites without his knowledge. He is wary about t
    7·1 answer
  • In general terms, a program that is broken into smaller units of code such as methods, is known as a ________
    6·1 answer
  • Three uses for Auto Formatting in Word 2016.
    5·1 answer
  • The four key stages with regards to data visualization workflow. Select one key stage and explain it briefly about that stage.St
    10·1 answer
  • Refer to the following code segment. You may assume that array arr1 contains elements arr1[0],arr[1],...,arr[N-1], where N = arr
    8·1 answer
  • Write a function safeOpen() that takes one parameter, filename — a string giving the pathname of the file to be opened for readi
    15·1 answer
  • What is the most effective way to demonstrate being prepared for an interview?
    13·1 answer
  • write a script to check command arguments. Display the argument one by one (use a for loop). If there is no argument provided, r
    6·1 answer
  • Given a constant named size with a value of 5, which statement can you use to define and initialize an array of doubles named ga
    12·1 answer
  • Explain the basic operations of a computer system​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!