Question

C++ write a function reverse the elemnets of an array so the last elemnets become the...

C++

write a function reverse the elemnets of an array so the last elemnets become the first , the second from the last become the second, and so forth. The funcition is to reverse the elemenss using either indexexes or pointers

0 0
Add a comment Improve this question Transcribed image text
Answer #1
void reverse(int a[], int size){
    int i = 0;
    int j = size-1;
    int t;
    while(i<j){
        t = a[i];
        a[i] = a[j];
        a[j] = t;
        i=i+1;
        j=j-1;
    }
}
Add a comment
Know the answer?
Add Answer to:
C++ write a function reverse the elemnets of an array so the last elemnets become the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++. Write a program that copies the contents of one array into another array but in...

    C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.           - in main()                    - define 2 arrays of type int, 10 elements each                              - initialize one array with numbers 1 through 10                              - initialize all elements of the second array to 0                    - call function reverseCopy with both arrays as arguments                    - display the values of array number 2 (reversed order)           - reverseCopy...

  • 4. (3 points) Consider the following function reverse, that attempts to reverse an array in place...

    4. (3 points) Consider the following function reverse, that attempts to reverse an array in place (i.e. without the use of additional storage). It does it by interchanging the first and last elements, then the second and second from last etc. All of the interchanges are done by calling function interchange. Here are the two functions and a main program: #include <iostream> using namespace std; void interchange(int x, int y) int temp: temp = x; x=y: y - tempi }...

  • Can someone help me understand this step by step (C++) Array Shifter and Array Reversal Write...

    Can someone help me understand this step by step (C++) Array Shifter and Array Reversal Write a function that accepts an array of doubles and the array's size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array...

  • C++ Write a function called reverseArray(char[] , int) that accepts in an array of chars and...

    C++ Write a function called reverseArray(char[] , int) that accepts in an array of chars and the size of the array.as parameters. The function should then create a new array that is the same size as the original array. The function should copy the elements from the first array into the second array in reverse order. So if the initial array is {'a' , 'b', 'c'} then the new array will be {'c', 'b', 'a'} Then in your main(), create...

  • In C: Write a function "MinMax" that takes as an argument an integer array, an integer...

    In C: Write a function "MinMax" that takes as an argument an integer array, an integer for the size of the array, and two integer pointers. The function should print nothing and return nothing but change the value of the first pointer to the minimum value in the array and change the value in the second pointer to the max value in the array.

  • Using C programming Write a function that reverses the elements of an array of integers so...

    Using C programming Write a function that reverses the elements of an array of integers so that the first becomes the last. Hint use a temporary variable for swapping values. Test with an odd and even number of elements

  • C++: Write a recursive function that displays the contents of an array in reverse order (from...

    C++: Write a recursive function that displays the contents of an array in reverse order (from the bottom up). The function declaration may look something like this: void displayReverse(char list[], int size, int startingIndex); The parameters are described as follows: list: The array to be displayed. size: The number of elements in the array. startingIndex: The element of the array currently being examined by the algorithm. The call to the function from main should look something like this, assuming that...

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

  • Write a C++ program that reads a string and creates a cyclical array. A cyclical array...

    Write a C++ program that reads a string and creates a cyclical array. A cyclical array is an array when the last element is pointing to the first one. Then write a loop that uses pointers and loops through the array starting from the first element and finishes after it visits the first element 5 times.

  • *****************************CODE SHOULD BE WRITTEN IN C++************************ Write a function to reverse an array of integers starting...

    *****************************CODE SHOULD BE WRITTEN IN C++************************ Write a function to reverse an array of integers starting from a given start index and a given end index. Note, the end index is inclusive. Add code to the given function below. *********************FUNCTION TO BE USED*********************************************** #include "problem1.h" void reverseArray(int arr[], int start, int end) { //written code } ************************************EXAMPLE************************************************ int[] a = {1,2,3}; reverseArray(a, 0, 2); //The content of a should be {3,2,1}. int[] a = {1,2,3}; reverseArray(a, 0, 1); //The content...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT