LegoDrifter

Nizi - 7 Selection sort

Nov 18th, 2020
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. int n;
  7. int tmp;
  8. scanf("%d",&n);
  9. int niza[n];
  10. for(int i=0;i<n;i++)
  11. {
  12. scanf("%d",&niza[i]);
  13. }
  14. for(int i=0;i<n;i++)
  15. {
  16. for(int j=i+1;j<n;j++)
  17. {
  18. if(niza[i]>niza[j])
  19. {
  20. tmp = niza[i];
  21. niza[i] = niza[j];
  22. niza[j] = tmp;
  23. }
  24. }
  25. }
  26. for(int i=0;i<n;i++)
  27. {
  28. printf("%d ",niza[i]);
  29. }
  30.  
  31. return 0;
  32. }
  33.  
Add Comment
Please, Sign In to add comment