Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3.  
  4. int main() {
  5.   uint64_t in_count = 0;
  6.  
  7.   uint32_t N = 1000*100;
  8.   for (uint32_t i = 0 ; i < N ; i++) {
  9.     const auto x = static_cast<double>(i)/N;
  10.     for (uint32_t j = 0 ; j < N ; j++) {
  11.       const auto y = static_cast<double>(j)/N;
  12.       if ((x*x + y*y) < 1) {
  13.     in_count++;
  14.       }
  15.     }
  16.   }
  17.  
  18.   double four = 4;
  19.   std::cout << std::fixed; std::cout.precision(10);
  20.   std::cout << (four*in_count / N) << std::endl;
  21.  
  22.   return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement