1/* 2 ************************************ **************************************** * ** 3 time: september 20, 2014 21:55:25 4 program name: movearr. C 5 by: xxnote 6 function: Move an integer array from the specified index K to one unit, and the last element is thrown away, change the element whose index is K to M 7 ******************************** **************************************** * ****** 8 */9 # include <stdio. h> 10 # define n 1011 12 INT iarr [N] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 13 void move (int * iarr, int K, int m); // move a position 14 void show (void); // display array 15 int main (void) 16 {17 printf ("the array before moving is \ n"); 18 show (); 19 move (iarr, 5,-1 ); 20 printf ("the array after moving is \ n"); 21 show (); 22 23 return 0; 24} 25 26 void move (int * iarr, int K, int m) 27 {28 int current, TMP, I; 29 30 TMP = iarr [k]; 31 for (I = K; I <N-1; I ++) 32 {33 current = TMP; 34 TMP = iarr [I + 1]; 35 iarr [I + 1] = current; 36} 37 iarr [k] = m; 38 39 return; 40} 41 42 void show (void) 43 {44 int I; 45 46 for (I = 0; I <n; I ++) 47 {48 printf ("% 3d", iarr [I]); 49} 50 printf ("\ n"); 51 return; 52}
Running effect:
Removes an array element from a specified index.