Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<time.h>
- #include <algorithm>
- using namespace std;
- int main() {
- int x;
- cout << "Podaj rozmiar tablicy ";
- cin >> x;
- cout << endl;
- int* tab = new int[x];
- float mediana;
- srand(time(NULL));
- for (int i = 0; i <x; i++) {
- tab[i] = rand() % 20;
- cout << tab[i] << " ";
- }
- sort(tab, tab + x);
- cout << endl;
- for (int i = 0; i < x; i++) {
- cout << tab[i] << " ";
- }
- cout << endl;
- if (x % 2 == 0) {
- mediana = ((tab[x / 2] + tab[(x / 2) - 1]) / 2);
- cout << "Mediana wynosi: " << mediana << endl;
- }
- else {
- mediana = (tab[(x / 2)]);
- cout << "Mediana wynosi: " << mediana << endl;
- }
- delete[]tab;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement