Advertisement
Guest User

insertion

a guest
Dec 13th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2. void insertion(int a[],int n)
  3. {
  4.  
  5. int i,j,temp;
  6. for(i=0; i<n-1; i++)
  7. {
  8. for(j=0; j<n-1-i; j++)
  9. {
  10. if(a[j]>a[j+1])
  11. {
  12. temp=a[j];
  13. a[j]=a[j+1];
  14. a[j+1]=temp;
  15. }
  16. }
  17. }
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. int main()
  28. {
  29. int i,j,n,temp,a[10];
  30. scanf("%d",&n);
  31. for(i=0; i<n; i++)
  32. {
  33. scanf("%d",&a[i]);
  34. }
  35. insertion( a, n);
  36. for(i=0; i<n; i++)
  37. {
  38. printf("%d ",a[i]);
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement