给定一个数组例如:int a[10]={1,2,3,4,5,6,7,8,9,10} 输入m 实现从m处的数组翻转
例如:
m=3,将数组的元素变为a[10]={8,9,10,1,2,3,4,5,6,7}
m=4 数组a变为a[10]={7,8,9,10,1,2,3,4,5,6}不允许使用库函数
#include <stdio.h>
int main(void)
{
int a[10]={1,2,3,4,5,6,7,8,9,10};
int n;
printf("Please input a number between 1 to 10: ");
scanf("%d", &n);
for(int i=0; i<n; i++){
int temp = a[9];
for(int j=8; j>=0; j--){
a[j+1] = a[j];
}
a[0] = temp;
}
for(int i=0; i<10; i++){
printf("%d ", a[i]);
}
return 0;
}