There are N integers, so that the order of the previous numbers is moved back M positions, and finally M numbers become the M numbers in front, write a function to achieve the above functions, enter N integers N integers and output adjusted N numbers in the main function.
#include "stdafx.h" #include "stdio.h" int main(int argc, char* argv[]) {void move(int array[20],int n,int m); int number[20],n,m,i; printf("how many numbers?"); scanf("%d",&n); printf("input %d numbers:\n",n); for(i=0; i<n; i++) scanf("%d",&number[i]); printf("how many place you want move?"); scanf("%d",&m); move(number,n,m); printf("now ,they are:\n"); for(i=0; i<n; i++) printf("%d ",number[i]); printf("\n"); return 0;
} void move(int array[20],int n,int m) // function that moves back once in a loop {int *p,array_end; array_end=*(array+n-1); for(p=array+n-1; p>array; p--) *p=*(p-1); *array=array_end; m--; if(m>0) move(array,n,m); Recursive call, when the number of loops M is reduced to 0, the call is stopped
}
|