Write a program to sort elements of array using Insert Sorting

Size of array is taken from user.. Elements are entered by user in any order... Sorting is performed..

Select To use this code as it is.. select and copy paste this code into code.cpp file :)
  1. #include<stdio.h> 

  2. main() 


  3. int a[100],n,k,i,j,temp; 

  4. printf("How many elements: \n"); 

  5. scanf("%d",&n); 

  6. printf("Enter the element of array: \n"); 

  7. for(i=0;i<=n-1;i++) 

  8. scanf("%d",&a[i]); 

  9. for(k=1;k<=n-1;k++) 


  10. temp=a[k]; 

  11. j=k-1; 

  12. //Coding by: Snehil Khanor 

  13. //http://WapCPP.blogspot.com 

  14. while((temp<a[j])&&(j>=0)) 


  15. a[j+1]=a[j]; 

  16. j=j-1; 


  17. a[j+1]=temp; 


  18. printf("Elements of array after sorting: \n"); 

  19. for(i=0;i<=n-1;i++) 

  20. printf("%d\n",a[i]); 

  21. getch();


Check out this stream