Advertisement
desdemona

miss lab1

Oct 2nd, 2015
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <gmpxx.h>
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7.  
  8. int main(int argc, char **argv)
  9. {
  10.     mpz_class d = 20; //dokladnosc
  11.     mpz_class n = 0; //ilosc cyfr
  12.     mpz_class p = 1; //okres
  13.    
  14.  
  15.     if(argc > 1)
  16.     {
  17.         d = argv[1];
  18.     }
  19.    
  20.     std::string sxn;
  21.     mpf_class xn;xn = 0;
  22.     mpf_class xn_sum; xn_sum = 0;
  23.     mpf_class xn_2sum; xn_2sum = 0;
  24.    
  25.     while(std::cin >> sxn)
  26.     {
  27.         xn = sxn;
  28.         xn_sum += xn;
  29.         xn_2sum += (xn*xn);
  30.         n+=1;
  31.     }
  32.    
  33.     mpf_class avg = xn_sum / n;
  34.     mpf_class vari = (xn_2sum / n) - avg*avg;
  35.    
  36.     std::cout << "zadana dokladnosc d=" << d << "\n";
  37.     std::cout << "wpisano n=" << n << " liczb\n";
  38.     std::cout << "srednia= " << avg << "\n";
  39.     std::cout << "wariacja= " << vari << "\n";
  40.    
  41.     //srednia
  42.     //wariancja
  43.     //okres ciagu
  44.    
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement