Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int x[10000];
  8. int y[10000];
  9.  
  10. const int a = 200;
  11. const int b = 200;
  12. const int pk = 200 * 200 * 3.141592;
  13. const double p = 400 * 400;
  14. const double PI = 3.1415926535;
  15.  
  16. int main()
  17. {
  18.     fstream file;
  19.     file.open("punkty.txt", ios::in);
  20.     for(int i=0; i<10000; i++)
  21.         file >> x[i] >> y[i];
  22.  
  23.  
  24.     for(int i=0; i<10000; i++)
  25.         if(pow(x[i] - 200, 2) + pow(y[i] - 200, 2) == 40000)
  26.             cout << x[i] << " " << y[i] << endl;
  27.  
  28.     cout << endl << endl << endl;
  29.  
  30.     int counter = 0;
  31.     double pi = 0;
  32.     for(int i=0; i<10000; i++)
  33.     {
  34.         if(pow(x[i]-a,2) + pow(y[i]-b, 2) < a*a || pow(x[i]-a,2) + pow(y[i]-b, 2) == a*a)
  35.             counter++;
  36.  
  37.         if( counter > 0 )
  38.                 pi = (counter * p) / ((i+1) * a * a);
  39.             if(i == 999 || i == 4999)
  40.             cout << pi << endl;
  41.     }
  42.     cout << pi << endl;
  43.  
  44.     pi = 0;
  45.     counter = 0;
  46.     double mistake;
  47.     for(int i=0; i<1700; i++)
  48.     {
  49.         if(pow(x[i]-a,2) + pow(y[i]-b, 2) < a*a)
  50.         {
  51.             counter++;
  52.         }
  53.  
  54.         if( counter > 0 )
  55.             pi = (counter * p) / ((i+1) * a * a);
  56.  
  57.         mistake = abs(PI - pi);
  58.         //cout << mistake << endl;
  59.     }
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement