THIS SHOULD BE DONE IN C Determining Experimentally Recall t

THIS SHOULD BE DONE IN C++ Determining Experimentally: Recall that is the ratio of a circle\'s circumference to its diameter and that we can calculate the area of a circle with the formula A=r2. Below is a circle enscribed within the unit square. What is the ratio of the areas of the enscribed circle to that of the unit square?

If we pick a random point within the unit square what is the probability that the point will also lie within the circle? If we repeat this experiment an arbitrarily large number of times the ratio of the number of points which lie within the circle to the number of points within the unit square (all of them) will approach /4. Using the language structures we have discussed write a program that will do the above experiment an arbitary (determined at run-time) number of times and report back the approximate value of .

Solution

#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace::std;
int main(void)
{
double output;
double times;
float x;
float y;
double raduis;
double line;
double ratio;
double hit=0.0; //here we are Initializing to known value
double repeat=0.0;

cout << \"it shows How many times to run the program: \";
cin >> times;

for(int i = 1; i <= times; i++)
{
x = (double)rand()/(double)RAND_MAX;//RAND_M is the highest number rand() that generates
y = (double)rand()/(double)RAND_MAX;//thus this gives more even distribution here

line = sqrt((x*x) + (y*y));
raduis = 1.0;

if (line > raduis)
{
cout << \"Points are off the circle\" << endl;
}
else
{
hit+=1.0;
}
repeat++; // we have to Do this if point is in or out
ratio = hit/repeat;
output = (4.0 * ratio);
cout << \"Computed PI = \" << output << endl;
}
return 0;
}

THIS SHOULD BE DONE IN C++ Determining Experimentally: Recall that is the ratio of a circle\'s circumference to its diameter and that we can calculate the area

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site