2019-08-21 10:10:08 +08:00
|
|
|
#include <iostream>
|
2017-12-24 01:30:49 +08:00
|
|
|
using namespace std;
|
2019-08-21 10:10:08 +08:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int n, k;
|
|
|
|
cout << "Enter size of array=\t";
|
|
|
|
cin >> n;
|
|
|
|
cout << "Enter Number of indeces u want to rotate the array to left=\t";
|
|
|
|
cin >> k;
|
2017-12-24 01:30:49 +08:00
|
|
|
int a[n];
|
2019-08-21 10:10:08 +08:00
|
|
|
cout << "Enter elements of array=\t";
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
cin >> a[i];
|
2017-12-24 01:30:49 +08:00
|
|
|
}
|
2019-08-21 10:10:08 +08:00
|
|
|
int temp = 0;
|
|
|
|
for (int i = 0; i < k; i++)
|
|
|
|
{
|
|
|
|
temp = a[0];
|
|
|
|
for (int j = 0; j < n; j++)
|
|
|
|
{
|
|
|
|
if (j == n - 1)
|
|
|
|
{
|
|
|
|
a[n - 1] = temp;
|
2017-12-24 01:30:49 +08:00
|
|
|
}
|
2019-08-21 10:10:08 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
a[j] = a[j + 1];
|
2017-12-24 01:30:49 +08:00
|
|
|
}
|
|
|
|
}
|
2019-08-21 10:10:08 +08:00
|
|
|
}
|
|
|
|
cout << "Your rotated array is=\t";
|
|
|
|
for (int j = 0; j < n; j++)
|
|
|
|
{
|
|
|
|
cout << a[j] << " ";
|
2017-12-24 01:30:49 +08:00
|
|
|
}
|
|
|
|
getchar();
|
|
|
|
return 0;
|
|
|
|
}
|