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...

  • 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.

  • 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.

  • Write a c program that finds the uncommon elements from two array elements using pointers only...

    Write a c program that finds the uncommon elements from two array elements using pointers only . For example : Enter the length of the array one : 5 Enter the elements of the array one: 9 8 5 6 3 Enter the length of the array two: 4 Enter the elements of the array two: 6 9 2 1 output: 8 5 3 2 1 void uncommon_ele(int *a, int n1, int *b, int n2, int *c, int*size); The function...

  • C programming Write a function that goes through all elements of an array of size n,...

    C programming Write a function that goes through all elements of an array of size n, and output the minimum and maximum values using pointers. Since C functions can only return one value, you must use pointers to output the minimum and maximum values from the function. You are not expected to print the values on the screen. Note: you will be assessed on the functionality and the coding style.

  • Write a C++ program that does the following : 1. Accepts array size from the keyboard....

    Write a C++ program that does the following : 1. Accepts array size from the keyboard. The size must be positive integer that is >= 5 and <= 15 inclusive . 2. Use the size from step 1 in order to create an integer array. Populate the created array with random integer values between 10 and 200. 3. Display the generated array. 4. Write a recursive function that displays the array in reverse order . 5. Write a recursive function...

  • Write a java function to process an array as follows: 1) reverse the contents of an...

    Write a java function to process an array as follows: 1) reverse the contents of an array 2) merge together two arrays 3) merge together two sorted arrays to yield a sorted array 4) append one array onto the end of another

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
ADVERTISEMENT