Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include<iostream>
  2. #include<time.h>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int x;
  9. cout << "Podaj rozmiar tablicy ";
  10. cin >> x;
  11. cout << endl;
  12. int* tab = new int[x];
  13.  
  14. float mediana;
  15.  
  16. srand(time(NULL));
  17.  
  18. for (int i = 0; i <x; i++) {
  19. tab[i] = rand() % 20;
  20. cout << tab[i] << " ";
  21. }
  22.  
  23. sort(tab, tab + x);
  24. cout << endl;
  25.  
  26. for (int i = 0; i < x; i++) {
  27. cout << tab[i] << " ";
  28. }
  29.  
  30. cout << endl;
  31. if (x % 2 == 0) {
  32. mediana = ((tab[x / 2] + tab[(x / 2) - 1]) / 2);
  33. cout << "Mediana wynosi: " << mediana << endl;
  34. }
  35. else {
  36. mediana = (tab[(x / 2)]);
  37. cout << "Mediana wynosi: " << mediana << endl;
  38. }
  39.  
  40.  
  41.  
  42. delete[]tab;
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement