Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- srand(time(NULL));
- int n, k;
- double x,y,S;
- n=100000; k=0;
- for (int i = 0; i < n; i++)
- {
- x = 2 * 1. * rand() / 32768;
- y = 2 * 1. * rand()/32768;
- if ((x-1)*(x-1)+(y-1)*(y-1)<=1)
- k=k+1;
- }
- cout << "k = ";
- cout << k << endl;
- S = 4. * k / n;
- cout << "S = ";
- cout << S;
- //cout << "x = ";
- //cout << x;
- //cout << "y = ";
- //cout << y;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement