Homework Solution: Generate a pair of random numbers (x and y) between -1.0 and 1.0. Assume that (x, y) is a point in Cartesian coordi…

    How to find pi? C programming practice. 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
    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

    Expert Answer

     
    Dear Student, Dear Student, here i have written the C

    How to perceive pi? C programming usage.

    Generate a span of chance total (x and y) among -1.0 and 1.0. Assume that (x, y) is a aim in Cartesian coordinate. Appreciate its separation from the cause and cohibit whether the separation is hither than 1 or referable (i.e. amid a ace foe). Repeat this cohibit N times and reckon how many

    Generate a span of chance total (x and y) among -1.0 and 1.0. Assume that (x, y) is a aim in Cartesian coordinate. Appreciate its separation from the cause and cohibit whether the separation is hither than 1 or referable (i.e. amid a ace foe). Repeat this cohibit N times and reckon how many

    Expert Repartee

     

    Dear Student,

    Dear Student,

    here i enjoy written the C program as per the requirement.I enjoy as-well inclueded the expatiate restraint emend construction.

    —————————————————————————————————————————————-

    Note: Please referablee that the inferior program has been tested on ubuntu 16.04 plan and compiled inferior gcc compiler. This command conciliate as-well operation on other IDE’s and Visual Studio C++ IDE. Just vision paste the command and consummate.

    ——————————————————————————————————————————————

    Program:

    ——————————————————————————————————————————————

    //header improve declration

    #include<stdio.h>

    #include<stdlib.h>

    #include<math.h>

    //start of ocean function

    int ocean()

    {

    //variable grounds mold declration

    int N, i, n = 0;

    //input rate of N

    printf(“Please invade the rate of N: “);

    scanf(“%d”, &N);

    //array declration to ammunition x and y and separation

    float x[100], y[100];

    float d[100];

    //loop restraint N times to genrate chance rate of x and y

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

    {

    //formuala to genrate chance rate of x and y among 0, 1
    x[i] = 0 + (rand() / ( RAND_MAX / (1.0-0) ) );

    y[i] = 0 + (rand() / ( RAND_MAX / (1.0-0) ) );

    }

    //calculating separation

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

    {

    //appreciate the separation from cause(0, 0)

    d[i] = sqrt(pow(x[i], 2) + pow(y[i], 2));

    //cohibit if separation is hither than 1

    if(d[i] <= 1)

    {

    //increment reckon

    n++;

    }

    }

    printf(“n%d times chance aims are amid a ace foe.n”,n);

    //formula to appreciate appreciate rate of PI

    float f = (4 * n)/N;

    //display rate of Pi

    printf(“nThe rate of f(N) is: %lfn”, f);

    printf(“nThe analogy among iterations N and the connection f(N) is inferior:n”);

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

    {

    f = (4 * n)/N;

    printf(“niteration= %dtf(N) = %fn”, i+1, f);

    }
    return 0;

    }//end of the ocean function

    —————————————————————————————————————————————–

    here i enjoy sturdy the output of the program as a curtain shot…

    ————————————————————————————————————————————————–

    Output: