Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void leftRotatebyOne(int arr[], int n)
- {
- int temp = arr[0], i;
- for (i = 0; i < n - 1; i++)
- arr[i] = arr[i + 1];
- arr[i] = temp;
- }
- void leftRotate(int arr[], int d, int n)
- {
- for (int i = 0; i < d; i++)
- leftRotatebyOne(arr, n);
- }
- int main()
- {
- int n, d;
- cin >> n >> d;
- int ara[n];
- for(int i = 0; i < n; i++)
- cin >> ara[i];
- leftRotate(ara, d, n);
- cout << "After Rotation" << endl;
- for(int i = 0; i < n; i++)
- cout << ara[i] << " ";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement