Insertion sort in C.

01 #include<stdio.h>
02 
03 int main()
04 {
05     int A[20], N, Temp, i, j;
06     printf("ENTER THE NUMBER OF TERMS...: ");
07     scanf("%d", &N);
08     printf("\n ENTER THE ELEMENTS OF THE ARRAY...:");
09 
10     for(i=0; i<N; i++)
11     {
12         scanf(" %d",&A[i]);
13     }
14     for(i=1; i<N; i++)
15     {
16         Temp = A[i];
17         j = i-1;
18         while(Temp<A[j] && j>=0)
19         {
20             A[j+1] = A[j];
21             j = j-1;
22         }
23         A[j+1] = Temp;
24     }
25     printf("\nTHE ASCENDING ORDER LIST IS...:\n");
26     for(i=0; i<N; i++)
27         printf("\n%d", A[i]);
28 
29     return 0;
30 }

 
 OUTPUT :
 
 ENTER THE NUMBER OF TERMS...: 4
 
 ENTER THE ELEMENTS OF THE ARRAY...:
 
     12
     22
     3
     15
 
 THE ASCENDING ORDER LIST IS...:
 
 3
 12
 15
 22