Examples:
Input:
arr[ ]= {1, 2, 3, 4, 5}
Output:
arr[ ] = {5, 4, 3, 2, 1}
Input:
arr[ ]= {10, 9, 8, 7, 6}
Output:
arr[ ] = {6, 7, 8, 9, 10}
#include <iostream>
#include <unordered_set>
using namespace std;
// Function to rearrange the arr
void reArrangeArr(int arr[], int n)
{
int l = 0, r = n - 1;
while (l < r)
{
int temp = arr[l];
arr[l] = arr[r];
arr[r] = temp;
l++;
r--;
}
}
// Function to print the arr
void printArr(int arr[], int n)
{
for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
}
// Main function
int main()
{
int arr[100], N, element;
cout << "Enter Number of elements: ";
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> arr[i];
}
reArrangeArr(arr, N);
printArr(arr, N);
return 0;
}
Output:
Enter Number of elements: 5
1 2 3 4 5
5 4 3 2 1
0 Comments