About 9,170,000 results
Open links in new tab
  1. c++ - Reverse Contents in Array - Stack Overflow

    reverse(arr, SIZE); return 0; int temp; for (int i = 0; i < count/2; ++i) arr[i] = temp; temp = arr[count-i-1]; arr[count-i-1] = arr[i]; arr[i] = temp; cout << temp << " "; Your loop only runs for half the length of the array when you divide the count by 2, so it only prints half of the array contents to the screen. Save this answer.

  2. How to Reverse an Array using STL in C++? - GeeksforGeeks

    Nov 15, 2024 · In this article, we will learn how to reverse an array using STL in C++. The most efficient way to reverse an array using STL is by using reverse () function. Let’s take a look at a simple example: This method reverses the array in-place i.e. it modifies the original array and rearranges it in reverse order.

  3. Array Reverse – Complete Tutorial - GeeksforGeeks

    Sep 25, 2024 · Given an array arr [], the task is to reverse the array. Reversing an array means rearranging the elements such that the first element becomes the last, the second element becomes second last and so on. Examples: Explanation: The first element 1 moves to last position, the second element 4 moves to second-last and so on.

  4. c++ - How to reverse elements in an array? - Stack Overflow

    Reverse the array first and introduce a second for loop for printing: for(auto el : myarray) std::cout << el << ' '; Or simply use std::reverse and let the Standard Library do the heavy lifting:

  5. Reverse an array upto a given position - GeeksforGeeks

    Feb 13, 2023 · Given an array arr[] containing N integers, the task is to rearrange the array such that the odd indexed elements are in reverse order. Examples: Input: arr[] = {5, 7, 6, 2, 9, 18, 11, 15} Output: {5, 15, 6, 18, 9, 2, 11, 7} Explanation: The elements at even index [5, 6, 9, 11] are unchanged and ele

  6. Reverse Elements of an Array in C++

    May 11, 2023 · Arrays can be reversed using the built-in reverse function in C++. Use the reverse function and supply the starting and ending addresses of the array as arguments. Syntax: reverse(arr,arr+n) will reverse the array arr of n elements. Code Implementation in C++. Output:

  7. Reverse an Array in C++ [3 Methods] - Pencil Programmer

    There are multiple ways to reverse an array in C++. Let’s discuss each of them. Method 1: Using an Extra Array. The idea is to create a new array and assign elements to it from the input array in reversed order. To do this, we simply have to: Initialize an array with values. Declare a new empty array of the same size.

  8. C++ Program to Reverse an Array - CodesCracker

    To reverse an array in C++ programming, you have to ask the user to enter the array's size and then add elements (of the given size) to the array. Now to reverse, do these things: Move the element at the first index to the last, and the element at the last index to the first.

  9. c++ - Swap elements in array to reverse an array - Stack Overflow

    Aug 14, 2014 · Write a function reverse that reverses the sequence of elements in an array. For example, if reverse is called with an array containing 1 4 9 16 9 7 4 9 11, then the array is changed to 11 9 4 7 9 16 9 4 1. So far, she told us in the reverse method, you need to swap for the array element.

  10. Reverse elements of an Array in C++ - PrepInsta

    In this method we will use inbuilt reverse function to reverse the array. reverse () is a predefined function in header file algorithm. It reverses the order of the elements in the range [first, last) of any container. reverse(arr, arr+n); for(int i=0; i<n; i++) . cout<<arr[i]<<" "; }

  11. Some results have been removed
Refresh