Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #define DIV (rand() - 1) / 32766.0 // defining a macro - everytime when we put DIV, it's replaced by this formula (rand() - 1) / 32766.0
- using namespace std;
- double PI_number(unsigned long long N)
- {
- double x, y;
- unsigned long long n = 0; // counts the number of the points included of the circle
- srand(time(nullptr));
- for(unsigned i = 0; i < N; ++i)
- {
- x = DIV;
- y = DIV;
- if(x * x + y * y <= 1)
- ++n;
- }
- return 4.0 * n / N;
- }
- int main()
- {
- cout << "PI has been estimated at " << PI_number(10000000000) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment