Advertisement
Courbe_Impliquee

sort

Dec 12th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <time.h>
  4. using namespace std;
  5. const int n=10;
  6.  
  7. int main()
  8. {
  9. float a[n],t;
  10. int min;
  11. for (int i=0; i<n; i++){
  12. a[i] = rand() %100 - 55;
  13. cout << a[i] << " ";
  14. }
  15. cout <<endl;
  16. for (int i=0;i<n;i++){
  17. if (a[i]>0){
  18. min = i;
  19. for(int j=i+1;j<n;j++){
  20. if(a[j]>0 && a[j]<a[min]){
  21. min=j;
  22. }
  23. }
  24. if (min!=i){
  25. t=a[i];
  26. a[i]=a[min];
  27. a[min]=t;
  28. }
  29. }
  30. }
  31. for(int i=0;i<n;i++)
  32. cout <<" "<< a[i];
  33. cout <<endl;
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement