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

please I want: A statement of the problem. An explanation of your solution. Pseu

ID: 3760922 • Letter: P

Question

please I want:

A statement of the problem.

An explanation of your solution.

Pseudocode.

for this code:

#include <stdio.h>

#include <stdlib.h>

void getRandomXY(float *x, float *y)

{

*x = (double)rand()/RAND_MAX;

*y = (double)rand()/RAND_MAX;

}

int insideCircle(float x, float y)

{

if(x*x + y*y <= 1)

return 1;

return 0;

}

int main()

{

float x, y, pi;

int i, numberOfDartsInSquare = 10000, numberOfDartsInCircle = 0;

for(i = 0; i < numberOfDartsInSquare; i++)

{

getRandomXY(&x, &y);

if(insideCircle(x, y))

numberOfDartsInCircle++;

}

pi = 4.0 * (float)numberOfDartsInCircle / numberOfDartsInSquare;

printf("The Monte Carlo PI estimate for %i number of darts is: %f ", numberOfDartsInSquare, pi);

}

Explanation / Answer

Hi, I believe I'm the one who wrote this code for you. Anyways, the explanation is herewith:

This program is to guess the PI value using MonteCarlo method. This method goes like this:

Given the side of a square, inscribe a circle inside the square, such that the radius of the circle equal to half of the side of the square, which means the circle touches the inside edges of the square.

Assume we are throwing a darts at random, The ratio of number of darts that fall inside the square but outside the circle to the number of darts fall inside the square is equal to the value of 4 times of PI.

The code is explained as comments here.

#include <stdio.h>
#include <stdlib.h>
void getRandomXY(float *x, float *y)   /*generates a random value for x & y between 0 and 32767.*/
{
*x = (double)rand()/RAND_MAX;
*y = (double)rand()/RAND_MAX;
}
int insideCircle(float x, float y)       /*Checks whether the point is within the circle or not.*/
{
if(x*x + y*y <= 1)           /*If x square + y square is less than or equal to 1.*/
return 1;               /*The point is inside the circle.*/
return 0;
}

int main()
{
float x, y, pi;
int i, numberOfDartsInSquare = 10000, numberOfDartsInCircle = 0;   /*No. of trials is 10000*/
for(i = 0; i < numberOfDartsInSquare; i++)       /*For each trial.*/
{
getRandomXY(&x, &y);           /*Get the random point (x,y), on the co-ordinate plane.*/
if(insideCircle(x, y))           /*If the point is inside the circle.*/
numberOfDartsInCircle++;   /*Increment the counter.*/
}
pi = 4.0 * (float)numberOfDartsInCircle / numberOfDartsInSquare;   /*PI = Number of darts in circle / No. of darts in square * 4.*/
printf("The Monte Carlo PI estimate for %i number of darts is: %f ", numberOfDartsInSquare, pi);
}