in Programming in C retagged by
2,370 views
4 votes
4 votes

main() {
    int c=0,x,i,y;
    for(i=0;i<N;i++) {
        x=random();y=random();
        if((x2+y2)<1) c++; } print(c); }

random() is a function which returns random number between $0$ or $1$, $N$ is a large number what is the output of the program?

in Programming in C retagged by
2.4k views

4 Comments

@Dhruv. I accept my mistake :) I applied wrong concept.
0
0
@Debashish I am in doubt how floating point could be applied here?

U mean decimal value?
0
0
how are u taking the probability of pi/4, can u please explain in a more simple way
0
0

1 Answer

1 vote
1 vote

This is monte carlo method to estimate value of pi. 

Value of c : N*π/4

 

For reference to monte carlo method: http://www.dartmouth.edu/~rc/classes/soft_dev/C_simple_ex.html