Advertisement
Guest User

...

a guest
Sep 18th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6. void Dane (){
  7. cout<< "Podaj ilosc elementow zbioru: ";
  8. cin<<m;
  9. cout<<"Podaj kolejno liczby: "<<endl;
  10. for(int i=0;i<m; i++)
  11. {
  12. cout<<"liczba("<< i+1 <<") = ";
  13. cin>> tab[i];
  14. cout<< endl;
  15. }
  16.  
  17.  
  18. }
  19.  
  20. void Wypisz(float m, float tab[])
  21. {
  22. for(int i=0; i<m; i++)
  23. cout<<tab[i]<< " ";
  24. cout<<endl;
  25. }
  26.  
  27. void Zamiana(float &a, float &b){
  28. float temp;
  29. temp = a;
  30. a = b;
  31. b = temp;
  32. }
  33.  
  34. void Selection_Sort(int m, float tab[]){
  35.  
  36. int i, j, k;
  37. for(i = 0; i<m; i++){
  38. k=i;
  39. for(j = i+1; j<m; j++) if(tab[j]>tab[k]) k=j;
  40. Zamaiana(tab[k], tab[i]);
  41. }
  42.  
  43. }
  44.  
  45. float liczby[20];
  46. int n;
  47. int main()
  48. {
  49. Dane(n, liczby);
  50. Wypisz(n, liczby);
  51. Selection_Sort(n,liczby);
  52. cout<<"Liczby uporządkowane: "<<endl;
  53. Wypisz(n, liczby);
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement