#include
using namespace std;
void Printf(int* arr,int len)
{
for (int i = 0;i < len;i++)
{
cout << arr[i] << " ";
}
}
void Shift_array(int* arr, int len)
{
int tmp = 0;
int hybird = 0;
cout << "please input the hybird: ";
cin >> hybird;
for (int i = 0;i < len;i++)
{
if (i == hybird)
{
break;
}
for (int j = 0;j < len - 1;j++)
{
tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
Printf(arr,len);
}
int main()
{
int arr[100] = { 0 };
cout << "please input the length of the array: ";
int len = 0;
cin >> len;
cout << "please input the global of the array: ";
for (int i = 0;i < len;i++)
{
cin >> arr[i];
}
Shift_array(arr, len);
return 0;
}
数组移位
最新推荐文章于 2023-04-23 09:42:57 发布