#include <stdio.h> #define N 30
void input_data(int * ,int); void operate_data(int *,int,int); void output_data(int * ,int); int main(int argc, char *argv[]) { int n,m,arr[N]; int *p =arr; printf("how many numbers?"); scanf("%d",&n); printf("please input %d number\n",n); input_data(p,n); printf("how many place you want move?"); scanf("%d",&m); printf("the source number is:\n"); p = arr; output_data(p,n); p = arr; operate_data(p,n,m); printf("the result is :\n"); p = arr; output_data(p,n); system("pause"); return 0; }
void input_data(int *arr , int n) { int i; for (i = 0 ; i < n ; i++) { scanf("%d" , arr++); } }
void operate_data(int *arr , int n ,int m) { int *arr_end,*p; int temp; arr_end = arr + n - 1; temp = *arr_end; for (p = arr_end;p > arr;p--) { *p = *(p - 1); } *p = temp; m --; if (m > 0) { operate_data(arr,n,m); } }
void output_data(int *arr , int n) { int i; for (i = 0 ; i < n ; i++) { printf("%d ",*arr++); } printf("\n"); }
|