1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include <stdio.h>; void swap(int *a, int *b); void moveArray(int a[], int n, int m);//轮移数组,其中n为总个数,m为轮移次数 int main (void) { int number[22]; int individualNumber, middleNumber; int i;//循环变量 while ((scanf("%d", &individualNumber), individualNumber) != 0) { scanf("%d", &middleNumber); for (i = 0 ; i < individualNumber ; i++) scanf("%d", &number[i]); moveArray(number, individualNumber, middleNumber); for (i = 0 ; i < individualNumber ; i++) { if (i != 0) putchar(' '); printf("%d", number[i]); } putchar('\n'); } return 0; } void moveArray(int a[], int n, int m) { if (m == 0) { return; } else { int temp, count; temp = a[0]; for (count = 0 ; count < n - 1 ; count++) a[count] = a[count+1]; a[n-1] = temp; moveArray(a, n, --m); } } void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; return; }
|