Advertisement
Salman_CUET_18

Untitled

Mar 1st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. void leftRotatebyOne(int arr[], int n)
  4. {
  5.     int temp = arr[0], i;
  6.     for (i = 0; i < n - 1; i++)
  7.         arr[i] = arr[i + 1];
  8.  
  9.     arr[i] = temp;
  10. }
  11. void leftRotate(int arr[], int d, int n)
  12. {
  13.     for (int i = 0; i < d; i++)
  14.         leftRotatebyOne(arr, n);
  15. }
  16. int main()
  17. {
  18.     int n, d;
  19.     cin >> n >> d;
  20.     int ara[n];
  21.     for(int i = 0; i < n; i++)
  22.         cin >> ara[i];
  23.     leftRotate(ara, d, n);
  24.     cout << "After Rotation" << endl;
  25.     for(int i = 0; i < n; i++)
  26.     cout << ara[i] << " ";
  27.     cout << endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement