PatrickSwayze

Untitled

Oct 30th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n,pom=0;
  9.     float srednia=0;
  10.     cout<<"Witaj w programie, ktory na podstawie wartosci w tablicy znajduje element minimalny, srednia i mediane. "<<endl;
  11.     cout<<"Wpisz ilosc elementow Twojej tablicy (n): ";
  12.     cin>>n;
  13.  
  14.     int a[20];
  15.  
  16.     for (int i=0;i<n;i++)
  17.     {
  18.         cout<<"Wpisz "<<i+1<<" wartosc tablicy: ";
  19.         cin>>a[i];
  20.     }
  21.  
  22.     int xmin=a[0];
  23.  
  24.     for (int i=0; i<n;i++)
  25.     {
  26.         if(a[i]<xmin) xmin=a[i];
  27.  
  28.         srednia=srednia+a[i];
  29.     }
  30.  
  31.     cout<<"Element minimalny wynosi: "<<xmin<<endl;
  32.     cout<<"Srednia wynosi: "<<srednia/n<<endl;
  33.     cout<<"Wartosci tablicy przed sortowaniem: "<<endl;
  34.     for (int i=0;i<n;i++)
  35.     {
  36.         cout<<a[i]<<endl;
  37.     }
  38.     //****************************************
  39.     for (int i=0;i<n;i++)
  40.     {
  41.         xmin=a[i];
  42.         int imin=i;
  43.  
  44.         for (int j=i+1;j<n;j++)
  45.         {
  46.             if (a[j]<a[i])
  47.             {
  48.                 imin=j;
  49.                 xmin=a[j];
  50.             }
  51.             int pom=a[imin];
  52.             a[imin]=a[i];
  53.             a[i]=pom;
  54.         }
  55.     }
  56.     cout<<"Wartosci tablicy po sortowaniu: "<<endl;
  57.     for (int i=0;i<n;i++)
  58.     {
  59.         cout<<a[i]<<endl;
  60.     }
  61.     float mediana=(a[1]+a[2])/2;
  62.     cout<<"Mediana wynosi: "<<mediana;
  63.  
  64.     return 0;
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment