Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- unsigned long long N = 1000000000;
- double pi()
- {
- double x, y;
- unsigned long long n = 0;
- double postep = 0.1;
- srand(time(nullptr));
- cout << "Wykonano 0%\n";
- for(unsigned long long i = 0; i < N; ++i)
- {
- if(1.0 * i / N >= postep)
- {
- system("cls"); // odświeżenie ekranu konsoli
- cout << "Wykonano " << 100.0 * i / N << "%\n";
- postep += 0.1;
- }
- x = 1.0 * rand() / RAND_MAX;
- y = 1.0 * rand() / RAND_MAX;
- if(x*x + y*y <= 1)
- ++n;
- }
- system("cls");
- return 4.0 * n / N;
- }
- int main()
- {
- double wynik = pi();
- cout << "Liczbe PI oszacowano na " << wynik << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement