2017-12-23 18:30:49 +01:00
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
2020-05-30 04:02:09 +00:00
|
|
|
int main() {
|
2019-08-21 10:10:08 +08:00
|
|
|
int n, k;
|
|
|
|
cout << "Enter size of array=\t";
|
|
|
|
cin >> n;
|
|
|
|
cout << "Enter Number of indices u want to rotate the array to right=\t";
|
|
|
|
cin >> k;
|
|
|
|
int a[n];
|
|
|
|
cout << "Enter elements of array=\t";
|
2020-05-29 23:26:30 +00:00
|
|
|
for (int i = 0; i < n; i++) cin >> a[i];
|
2019-08-21 10:10:08 +08:00
|
|
|
int temp = 0;
|
2020-05-30 04:02:09 +00:00
|
|
|
for (int i = 0; i < k; i++) {
|
2019-08-21 10:10:08 +08:00
|
|
|
temp = a[n - 1];
|
2020-05-30 04:02:09 +00:00
|
|
|
for (int j = n - 1; j >= 0; j--) {
|
|
|
|
if (j == 0) {
|
2019-08-21 10:10:08 +08:00
|
|
|
a[j] = temp;
|
2020-05-30 04:02:09 +00:00
|
|
|
} else {
|
2019-08-21 10:10:08 +08:00
|
|
|
a[j] = a[j - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cout << "Your rotated array is=\t";
|
2020-05-30 04:02:09 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
2019-08-21 10:10:08 +08:00
|
|
|
cout << a[i] << " ";
|
2017-12-23 18:30:49 +01:00
|
|
|
}
|
|
|
|
}
|