answersLogoWhite

0


Best Answer

//Program to calculate the value of pi using monte carlo method:

/*

NADEEM AHMAD

MCA 2012

NITISH HOODA

M TECH 2012

SHARDA UNIVERSITY

GREATER NOIDA*/

#include<stdlib.h>

#include<stdio.h>

#include<math.h>

#include<string.h>

#include<conio.h>

#define SEED 35791246

void main(int argc, char* argv)

{

int niter=0;

double x,y;

int i,count=0; /* # of points in the 1st quadrant of unit circle */

double z;

double pi;

printf("Enter the number of iterations used to estimate pi: ");

scanf("%d",&niter);

/* initialize random numbers */

srand(SEED);

count=0;

for ( i=0; i<niter; i++) {

x = (double)rand()/RAND_MAX;

y = (double)rand()/RAND_MAX;

z = x*x+y*y;

if (z<=1) count++;

}

pi=(double)count/niter*4;

printf("# of trials= %d , estimate of pi is %g \n",niter,pi);

getch();

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you Program to calculate the value of pi using Monte Carlo method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What has the author Reuven Y Rubinstein written?

Reuven Y. Rubinstein has written: 'Simulation and the Monte Carlo Method' 'Simulation and the monte carlo method' -- subject(s): Monte Carlo method, Digital computer simulation 'Monte Carlo optimization, simulation, and sensitivity of queuing networks' -- subject(s): Mathematical models, Monte Carlo method, Queuing theory


What has the author J M Hammersley written?

J. M. Hammersley has written: 'Monte Carlo methods' -- subject(s): Probabilities, Monte Carlo method


What has the author William L Dunn written?

William L. Dunn has written: 'Exploring Monte Carlo methods' -- subject(s): Monte Carlo method


What has the author Y A Schreider written?

Y. A. Schreider has written: 'The Monte Carlo method'


What has the author Ralf Korn written?

Ralf Korn has written: 'Monte Carlo methods and models in finance and insurance' -- subject(s): Mathematics, Monte Carlo method, Business mathematics, Insurance


What has the author C Moglestue written?

C. Moglestue has written: 'Monte Carlo simulation of semiconductor devices' -- subject(s): Computer simulation, Mathematical models, Monte Carlo method, Semiconductors


Is Monte Carlo in Monaco?

Yes, Monte Carlo is in Monaco.


What has the author Chester Lewellyn Olson written?

Chester Lewellyn Olson has written: 'A Monte Carlo investigation of the robustness of multivariate analysis of variance' -- subject(s): Monte Carlo method, Multivariate analysis


What is the distance in kilometres from montpellier France to Monte Carlo France?

Monte Carlo is in Monaco ! There are 350 kms from Montpellier to Monte Carlo


Will 2010 Monte Carlo front cap fit a 1986 Monte Carlo?

There is no such thing as a 2010 Monte Carlo, so the answer would be no


What coutry is Monte Carlo?

The town of Monte Carlo is in the country of Monaco


Which country is Monte Carlo?

The town of Monte Carlo is in the country of Monaco