Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdbool.h>
  4. using namespace std;
  5. void bubbleSort(double array[], int size)
  6. {
  7.     bool isSorted = false; double pom;
  8.     while(isSorted == false)
  9.     {
  10.         isSorted = true;
  11.         for(int i=0; i<size -1; i++)
  12.         {
  13.             if(array[i] > array[i+1])
  14.             {
  15.                 pom = array[i];
  16.                 array[i] = array[i+1];
  17.                 array[i+1] = pom;
  18.                 isSorted = false;
  19.             }
  20.         }
  21.     }
  22. }
  23. double mediana(double array[], int size)
  24. {
  25.     if(size%2 == 0)
  26.     {
  27.         double el_1 = array[(size-1)/2];
  28.        // printf("el_1 = %lf",el_1);
  29.         double el_2 = array[ ((size-1)/2) +1];
  30.       //  printf("el_2 = %lf",el_2);
  31.         return (el_1 + el_2) / 2;
  32.     }
  33.     else
  34.     {
  35.         int indeks_temp = (size+1)/2;
  36.         return array[indeks_temp-1];
  37.     }
  38. }
  39. double srednia(double array[], int size)
  40. {
  41.     double sum = 0;
  42.     for(int i=0; i<size; i++)
  43.         sum+=array[i];
  44.     return sum/size;
  45. }
  46. double kwartyl_pierwszy(double array[], int size)
  47. {
  48.         return array[(size/4)];
  49. }
  50. double kwartyl_trzeci(double array[], int size)
  51. {
  52.         return array[((3*size)/4)];
  53. }
  54. double odchylene_cwiartkowe(double array[], int size)
  55. {
  56.     return (kwartyl_trzeci(array,size) - kwartyl_pierwszy(array,size)) / 2;
  57. }
  58. int main()
  59. {
  60.     int sizeofArray;
  61.     printf("Podaj ilosc elementow: ");
  62.     scanf("%d",&sizeofArray);
  63.     double tab[sizeofArray];
  64.     for(int i=0; i<sizeofArray; i++)
  65.     {
  66.         scanf("%lf",&tab[i]);
  67.     }
  68.     bubbleSort(tab,sizeofArray);
  69.     printf("Mediana wynosi: %lf\n", mediana(tab,sizeofArray));
  70.     printf("Srednia wynosi: %lf\n", srednia(tab,sizeofArray));
  71.     kwartyl_pierwszy(tab,sizeofArray);
  72.     kwartyl_trzeci(tab,sizeofArray);
  73.     printf("Kwartyl pierwszy: %lf\n", kwartyl_pierwszy(tab, sizeofArray));
  74.     printf("Kwartyl trzeci: %lf\n", kwartyl_trzeci(tab, sizeofArray));
  75.     printf("Odchylenie cwiartkowe: %lf\n", odchylene_cwiartkowe(tab, sizeofArray));
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement