Insert sorting of Arrays:
1 # include <stdio. h>
2 int main ()
3 {
4
5 int a [11] = {40,100,}; // 10 member
6
7 int temp1, temp2, number, end, I, j;
8
9 printf ("original array is: \ n ");
10
11 for (I = 0; I <11; I ++) // output 11 member, if a [10] = 0, it indicate it was init already
12
13 printf ("% 5d", a [I]);
14
15 printf ("\ n ");
16
17 printf ("insert a new number :");
18
19 scanf ("% d", & number );
20
21 end = a [9];
22
23 if (number> end)
24
25 a [10] = number;
26
27 else
28
29 {
30 for (I = 0; I <10; I ++)
31
32 {
33 if (a [I]> number)
34
35 {
36 temp1 = a [I];
37
38 a [I] = number;
39
40 for (j = I + 1; j <11; j ++)
41
42 {
43 temp2 = a [j];
44
45 a [j] = temp1;
46
47 temp1 = temp2;
48
49}
50
51 break;
52
53}
54
55}
56
57}
58
59 for (I = 0; I <11; I ++)
60 printf ("% 6d", a [I]);
61
62 printf ("\ n ");
63
64 return 0;
65
66}
Mian @ mian :~ /Public/code $./input_cmd_array
Original array is:
1 4 6 9 13 16 19 28 40 100 0
From zhengmian