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 invent pi? C programming exercitation.

    Generate a couple of stray quantity (x and y) among -1.0 and 1.0. Assume that (x, y) is a subject-matter in Cartesian coordinate. Count its remoteness from the spring and hinder whether the remoteness is near than 1 or not attributable attributable attributable attributable attributable attributable (i.e. amid a item dispersion). Repeat this hinder N times and prize how many

    Generate a couple of stray quantity (x and y) among -1.0 and 1.0. Assume that (x, y) is a subject-matter in Cartesian coordinate. Count its remoteness from the spring and hinder whether the remoteness is near than 1 or not attributable attributable attributable attributable attributable attributable (i.e. amid a item dispersion). Repeat this hinder N times and prize how many

    Expert Confutation

     

    Dear Student,

    Dear Student,

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

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

    Note: Please not attributable attributable attributable attributable attributablee that the inferiorneath program has been tested on ubuntu 16.04 rule and compiled inferior gcc compiler. This edict gain as-well effect on other IDE’s and Visual Studio C++ IDE. Just delineation paste the edict and complete.

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

    Program:

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

    //header rasp declration

    #include<stdio.h>

    #include<stdlib.h>

    #include<math.h>

    //start of ocean function

    int ocean()

    {

    //variable basis fashion declration

    int N, i, n = 0;

    //input appreciate of N

    printf(“Please penetrate the appreciate of N: “);

    scanf(“%d”, &N);

    //array declration to ammunition x and y and remoteness

    float x[100], y[100];

    float d[100];

    //loop coercion N times to genrate stray appreciate of x and y

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

    {

    //formuala to genrate stray appreciate 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 remoteness

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

    {

    //count the remoteness from spring(0, 0)

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

    //hinder if remoteness is near than 1

    if(d[i] <= 1)

    {

    //increment prize

    n++;

    }

    }

    printf(“n%d times stray subject-matters are amid a item dispersion.n”,n);

    //formula to count prize appreciate of PI

    float f = (4 * n)/N;

    //display appreciate of Pi

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

    printf(“nThe connection among iterations N and the association f(N) is inferiorneath: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 resolute the output of the program as a shelter shot…

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

    Output: