MeehoweCK

Untitled

Apr 19th, 2021
503
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. const unsigned short ROZMIAR = 10;
  8.  
  9. int main()
  10. {
  11.     double min, max, suma = 0;
  12.     cout << "Podaj liczbe najmniejsza i najwieksza: ";
  13.     cin >> min >> max;
  14.     if(max < min)
  15.         swap(min, max);
  16.  
  17.     double Dane[ROZMIAR];
  18.     srand(time(nullptr));
  19.     for(short i = 0; i < ROZMIAR; ++i)
  20.     {
  21.         Dane[i] = min + (max - min) * rand() / RAND_MAX;
  22.         cout << Dane[i] << '\t';
  23.         suma += Dane[i];
  24.     }
  25.     cout << endl << "srednia = " << suma / ROZMIAR << endl;
  26.  
  27.     unsigned short Index[ROZMIAR];
  28.     for(unsigned short i = 0; i < ROZMIAR; ++i)
  29.         Index[i] = i;
  30.  
  31.     unsigned short nr_elementu;
  32.     double wartosc_min;
  33.  
  34.     for(unsigned short i = 0; i < ROZMIAR - 1; ++i)
  35.     {
  36.         wartosc_min = max;
  37.         for(unsigned short j = i; j < ROZMIAR; ++j)
  38.             if(Dane[Index[j]] < wartosc_min)
  39.             {
  40.                 wartosc_min = Dane[Index[j]];
  41.                 nr_elementu = j;
  42.             }
  43.         swap(Index[i], Index[nr_elementu]);
  44.     }
  45.  
  46.     suma = 0;
  47.     for(unsigned short i = 0; i < ROZMIAR; ++i)
  48.     {
  49.         cout << Index[i] << '\t';
  50.         if(i >= 3 && i < ROZMIAR - 3)
  51.             suma += Dane[Index[i]];
  52.     }
  53.  
  54.     cout << endl << "Srednia liczb bez pominietych = " << suma / (ROZMIAR - 6) << endl;
  55.     return 0;
  56. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×