Guest User

Untitled

a guest
Dec 11th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. double a, b;
  9. long T = 0;
  10. long R;
  11. long ilosc;
  12.  
  13. srand(time(NULL));
  14. cout << "Na podstawie ilu punktów znalesc wartosc liczby pi? ";
  15. cin>> ilosc;
  16. for(R=0; R<ilosc; R++)
  17. {
  18. a = (double)rand()/(RAND_MAX);
  19. b = (double)rand()/(RAND_MAX);
  20.  
  21. if (a*a+b*b<=1) T++;
  22.  
  23. }
  24.  
  25. cout << "liczba pi ma wartosc : " << (double) (4*T)/R;
  26.  
  27. cin.ignore();
  28. getchar();
  29. return 0;
  30. }
Add Comment
Please, Sign In to add comment