Advertisement
AJTAMjid2000

Untitled

Nov 29th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. //Bubble sort
  2. #include<stdio.h>
  3. int main()
  4. {
  5. int i,j,n,temp;
  6. scanf("%d",&n);
  7. int a[n];
  8. for(i=0;i<n;i++)
  9. {
  10. scanf("%d",&a[i]);
  11.  
  12. }
  13. for(i=0;i<n;i++)
  14. {
  15.  
  16.  
  17. for (j=i+1;j<n;j++)
  18. {
  19.  
  20. if(a[i]>a[j])
  21. {
  22.  
  23. temp=a[i];
  24. a[i]=a[j];
  25. a[j]=temp;
  26.  
  27. }
  28.  
  29.  
  30.  
  31. }
  32.  
  33.  
  34.  
  35.  
  36. }
  37. for(i=0;i<n;i++)
  38. {
  39. printf("%d\t",a[i]);
  40. }
  41.  
  42. printf("\n");
  43.  
  44. return 0;
  45. }
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement