Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define SIZE 5 // większe od 0
  4.  
  5. int main()
  6. {
  7.     printf("Podaj 5 liczb do sredniej: ");
  8.  
  9.     double tab[SIZE], suma = 0, srednia, wariancja = 0;
  10.     for(int i = 0; i < SIZE; i++ )
  11.     {
  12. //        double buff;
  13. //        scanf("%lf", &buff);
  14. //        tab[i] = buff;
  15.         tab[i] = i+5;  // ma byc zakomentowane
  16.     }
  17.  
  18.     for(int i = 0; i < SIZE; i++ )
  19.         suma += tab[i];
  20.  
  21.     srednia = suma / SIZE;
  22.  
  23.     for(int i = 0; i < SIZE; i++ )
  24.         wariancja += pow(tab[i] - srednia, 2);
  25.  
  26.     wariancja /= SIZE - 1;
  27.  
  28.     printf("Średnia = %lf\nWariancja = %lf\n", srednia, wariancja);
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement