Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1: Let\'s say that you draw a square around the top right quadrant of a

ID: 3585179 • Letter: Q

Question


Question 1: Let's say that you draw a square around the top right quadrant of a circle. If the circle has a radius r, then the square that covers the top right quadrant of the circle will coveran area rA2 The area of a circle is Pi*rA2. Given that we're dealing with only the top right quadrant, the area will be (Pi*rA2)/4. The ratio of the area oT the top right quadrant of the circle to the square that covers it would Generate 4 billion random dots that fall within that square. Figure out how many of them fall inside the circle, and how many fall outside of it. If you divide the number of dots that fall within the circle by the total number of dots (the ones that fell anywhere irn the entire square), you should get roughly the same ratio as the one you computed above. Froim there, you should be able to calculate the value of PI. Btw, this is known as the monte carlo method, if you wanna google stuff.

Explanation / Answer

#include<iostream>
#include<math.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int main(){

    srand(time(NULL));
    double x,y;
    double ratio;
    int count;
    long loop_cnt;

    count = 0;
    loop_cnt = 0;
    while(loop_cnt <4000000000){ // Assuming r = 20;
         x = rand() % 20;
         y = rand() % 20;
         if (sqrt(x*x + y*y) < 20)
            count++;
         loop_cnt++;
         cout << loop_cnt << endl;
    }
    cout << "The value is " << count/loop_cnt << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote