Question 1: Let\'s say that you draw a square around the top right quadrant of a
ID: 3585179 • Letter: Q
Question
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;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.