Advertisement
Guest User

Untitled

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