Examples:

Input:

arr[]= {1,2,3,4,5,6}

d = 3

Output:

arr[ ] = {4,5,6,1,2,3}


Input:

arr[ ]= {1, 2, 3, 4, 5, 6}

d = 2

Output:

arr[]= {3, 4, 5, 6, 1, 2}

#include <bits/stdc++.h>
using namespace std;
void reverse(int arr[], int start, int end)
{
    int temp;
    while (start < end)
    {
        temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}
int main()
{
    int arr[100],n,d;
   
    cout << "Enter The initial array size :";
    cin >> n;
    cout << "Enter The initial array :";
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    cout << "Enter The rotating  array index :";
    cin >> d;
    reverse(arr, 0, d - 1);
    reverse(arr, d, n - 1);
    reverse(arr, 0, n - 1);
    cout << "The left reversed array by" << d << "elements is:";
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    return 0;
}

Output:


Enter The initial array size :7
Enter The initial array :1 2 3 4 5 6 7
Enter The rotating  array index :3
The left reversed array by3elements is:4 5 6 7 1 2 3