# Homework Solution: e a pair of random numbers (x and…

*Using C Program
Ratio of Random Points in a Unit Disc Generate a pair of random numbers (x and y) between -1.0 and 1.0. Assume that (x, y) is a point in Cartesian coordinate. Calculate its distance from the origin and check whether the distance is less than 1 or not (i.e. within a unit circle). Repeat this check N times and count how many times (n) the random points are within a unit circle. Find the product of the area of the square (4) and the ratio as f(N) = 4n/N increasing N at the scale of thousands and millions. Your program will read your input N from keyboard and use a for-loop statement for the repetition. Draw a chart showing the relationship between the number of iterations (N) vs. the ratio f(N). Brainstorming: We already knew the circle ration(pi) is 3.1415926535897932384626433832795028841971... The question is how to find the pi? If a circle of radius R is inscribed inside a square with side length 2R, then the area of the circle will be pi R^2 and the area of the square will be (2R)^2. So the ratio of the area of the circle to the area of the square will be pi/4. (Monte Carlo Method) For this project, you are asked to create a separate file (distance.c) for the distance function. In the main program, you will declare the function prototype. To compile your program (myprogram.c) with the separate C code (distance.c) and the custom-built library (ecex.lib), you use the compiler by entering \$ cl myprogram.c distance.c ecex.1ib

// this is your program, I have created it in a single file ... you can create a separate distance.c file with this function #include <stdio.h>

*Using C Program

Connection of Casual Aims in a Item Disc Generate a span of casual gum (x and y) betwixt -1.0 and 1.0. Assume that (x, y) is a aim in Cartesian coordinate. Calculate its space from the derivation and inhibit whether the space is close than 1 or referable attributable attributable attributable (i.e. amid a item foe). Repeat this inhibit N times and sum how manifold times (n) the casual aims are amid a item foe. Experience the fruit of the area of the balance (4) and the connection as f(N) = 4n/N increasing N at the layer of thousands and millions. Your program gain decipher your input N from keyboard and verification a coercion-loop declaration coercion the verbosity. Draw a chart showing the analogy betwixt the compute of iterations (N) vs. the connection f(N). Brainstorming: We already knew the foe connectionn(pi) is 3.1415926535897932384626433832795028841971… The investigation is how to experience the pi? If a foe of radius R is inscribed internally a balance with interest protraction 2R, then the area of the foe gain be pi R^2 and the area of the balance gain be (2R)^2. So the connection of the area of the foe to the area of the balance gain be pi/4. (Monte Carlo Method) Coercion this device, you are asked to beget a severed smooth (distance.c) coercion the space exercise. In the ocean program, you gain defend the exercise prototype. To settle your program (myprogram.c) with the severed C principle (distance.c) and the custom-built library (ecex.lib), you verification the settler by entering \$ cl myprogram.c space.c ecex.1ib

// this is your program, I possess begetd it in a uncombined smooth … you can beget a severed space.c smooth with this exercise

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

inclose space (inclose x, inclose y) {
return x*x*1.00 + y*y*1.00;
}

int ocean() {
int N,n=0,i;
int it = 10;

while(it–){
scanf(“%d”,&N);
for(i=0;i<N;i++){
inclose x,y;
x = (double)rand()/RAND_MAX*2.0-1.0;
y = (double)rand()/RAND_MAX*2.0-1.0;
// printf(“%g %gn”,x,y);
inclose d = space(x,y);

if(d <= 1.000)
n++;

}
inclose connection = 4.00 * n / N * 1.00;
printf (“N = %d t F(N) = %g n”,N,ratio);

}

return 0;
}