SlideShare ist ein Scribd-Unternehmen logo
1 von 2
It is proposed to caluculate pi by using the Monte Carlo method. A circle of radius 1 is inside a
square of side 2. We count how many of m random points in the square happen to lie in the
circle. Assume that the error is 1/square root m. How many points must be taken to obtain pi
with three accurate figures? Write a program to find the answer.
Solution
/* Program to compute Pi using Monte Carlo methods */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define SEED 35791246
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  ",niter,pi);
}

Weitere ähnliche Inhalte

Ă„hnlich wie It is proposed to caluculate pi by using the Monte Carlo method- A cir.docx

SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptxSanketAde1
 
Lesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbersLesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbersPVS-Studio
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruzrpmcruz
 
Approximating Value of pi(Π) using Monte Carlo Iterative Method
Approximating Value of pi(Π) using Monte Carlo Iterative MethodApproximating Value of pi(Π) using Monte Carlo Iterative Method
Approximating Value of pi(Π) using Monte Carlo Iterative MethodNischal Lal Shrestha
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfjanakim15
 
Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]Vivek Kumar Sinha
 
PRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptxPRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptxAbhinavGupta257043
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docxjosies1
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxShamshad
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manualkamesh dagia
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programsPrasadu Peddi
 

Ă„hnlich wie It is proposed to caluculate pi by using the Monte Carlo method- A cir.docx (20)

SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAMSIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
cpract.docx
cpract.docxcpract.docx
cpract.docx
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
 
17 Jo P May 08
17 Jo P May 0817 Jo P May 08
17 Jo P May 08
 
Lesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbersLesson 9. Pattern 1. Magic numbers
Lesson 9. Pattern 1. Magic numbers
 
C Programming
C ProgrammingC Programming
C Programming
 
Python for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo CruzPython for Scientific Computing -- Ricardo Cruz
Python for Scientific Computing -- Ricardo Cruz
 
Progr3
Progr3Progr3
Progr3
 
Approximating Value of pi(Π) using Monte Carlo Iterative Method
Approximating Value of pi(Π) using Monte Carlo Iterative MethodApproximating Value of pi(Π) using Monte Carlo Iterative Method
Approximating Value of pi(Π) using Monte Carlo Iterative Method
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
C-LOOP-Session-2.pptx
C-LOOP-Session-2.pptxC-LOOP-Session-2.pptx
C-LOOP-Session-2.pptx
 
Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]Lab manualsahu[et&amp;t]
Lab manualsahu[et&amp;t]
 
PRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptxPRACTICAL FILE(COMP SC).pptx
PRACTICAL FILE(COMP SC).pptx
 
c programing
c programingc programing
c programing
 
Programming egs
Programming egs Programming egs
Programming egs
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
Chapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docxChapter 1 Programming Fundamentals Assignment.docx
Chapter 1 Programming Fundamentals Assignment.docx
 
25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual25422733 c-programming-and-data-structures-lab-manual
25422733 c-programming-and-data-structures-lab-manual
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 

Mehr von michael1810

Judging from their relative positions in the Periodic Table- which ato.docx
Judging from their relative positions in the Periodic Table- which ato.docxJudging from their relative positions in the Periodic Table- which ato.docx
Judging from their relative positions in the Periodic Table- which ato.docxmichael1810
 
John Corporation has three investments that are classified as noncontr.docx
John Corporation has three investments that are classified as noncontr.docxJohn Corporation has three investments that are classified as noncontr.docx
John Corporation has three investments that are classified as noncontr.docxmichael1810
 
John Smith worked in the stockyard of a large building supply company-.docx
John Smith worked in the stockyard of a large building supply company-.docxJohn Smith worked in the stockyard of a large building supply company-.docx
John Smith worked in the stockyard of a large building supply company-.docxmichael1810
 
John has tremendous technical skills and frequently comes up with valu.docx
John has tremendous technical skills and frequently comes up with valu.docxJohn has tremendous technical skills and frequently comes up with valu.docx
John has tremendous technical skills and frequently comes up with valu.docxmichael1810
 
Joe Frecaso was recently hired as the controller for Larson Cement Com.docx
Joe Frecaso was recently hired as the controller for Larson Cement Com.docxJoe Frecaso was recently hired as the controller for Larson Cement Com.docx
Joe Frecaso was recently hired as the controller for Larson Cement Com.docxmichael1810
 
Java Write a method that takes as a parameter a one dimensional array.docx
Java Write a method that takes as a parameter a one dimensional array.docxJava Write a method that takes as a parameter a one dimensional array.docx
Java Write a method that takes as a parameter a one dimensional array.docxmichael1810
 
Java Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxJava Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxmichael1810
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxmichael1810
 
Java Language Which of the following statements is true- Select all th.docx
Java Language Which of the following statements is true- Select all th.docxJava Language Which of the following statements is true- Select all th.docx
Java Language Which of the following statements is true- Select all th.docxmichael1810
 
It-'s virtualization topic Would anyone please expalin what is the di.docx
It-'s virtualization topic  Would anyone please expalin what is the di.docxIt-'s virtualization topic  Would anyone please expalin what is the di.docx
It-'s virtualization topic Would anyone please expalin what is the di.docxmichael1810
 
For each pair of substance identify the substance that is likely to ha.docx
For each pair of substance identify the substance that is likely to ha.docxFor each pair of substance identify the substance that is likely to ha.docx
For each pair of substance identify the substance that is likely to ha.docxmichael1810
 
For each of the requirements listed in the table below- 1- Please iden.docx
For each of the requirements listed in the table below- 1- Please iden.docxFor each of the requirements listed in the table below- 1- Please iden.docx
For each of the requirements listed in the table below- 1- Please iden.docxmichael1810
 
For Contingent Liability- When do you disclose it- When do you record.docx
For Contingent Liability- When do you disclose it- When do you record.docxFor Contingent Liability- When do you disclose it- When do you record.docx
For Contingent Liability- When do you disclose it- When do you record.docxmichael1810
 
For each of the abstract data types (ADTs) that we have analyzed in th.docx
For each of the abstract data types (ADTs) that we have analyzed in th.docxFor each of the abstract data types (ADTs) that we have analyzed in th.docx
For each of the abstract data types (ADTs) that we have analyzed in th.docxmichael1810
 
For each form of transport plot the value of overall benefits against.docx
For each form of transport plot the value of overall benefits against.docxFor each form of transport plot the value of overall benefits against.docx
For each form of transport plot the value of overall benefits against.docxmichael1810
 
Fluid Mechanics The water surface is at the position shown at t - 0 se.docx
Fluid Mechanics The water surface is at the position shown at t - 0 se.docxFluid Mechanics The water surface is at the position shown at t - 0 se.docx
Fluid Mechanics The water surface is at the position shown at t - 0 se.docxmichael1810
 
Fluctuation in inflation can occur in the short or long term- For exam.docx
Fluctuation in inflation can occur in the short or long term- For exam.docxFluctuation in inflation can occur in the short or long term- For exam.docx
Fluctuation in inflation can occur in the short or long term- For exam.docxmichael1810
 
First National Bank charges 11-2 percent compounded monthly on its bus (1).docx
First National Bank charges 11-2 percent compounded monthly on its bus (1).docxFirst National Bank charges 11-2 percent compounded monthly on its bus (1).docx
First National Bank charges 11-2 percent compounded monthly on its bus (1).docxmichael1810
 

Mehr von michael1810 (18)

Judging from their relative positions in the Periodic Table- which ato.docx
Judging from their relative positions in the Periodic Table- which ato.docxJudging from their relative positions in the Periodic Table- which ato.docx
Judging from their relative positions in the Periodic Table- which ato.docx
 
John Corporation has three investments that are classified as noncontr.docx
John Corporation has three investments that are classified as noncontr.docxJohn Corporation has three investments that are classified as noncontr.docx
John Corporation has three investments that are classified as noncontr.docx
 
John Smith worked in the stockyard of a large building supply company-.docx
John Smith worked in the stockyard of a large building supply company-.docxJohn Smith worked in the stockyard of a large building supply company-.docx
John Smith worked in the stockyard of a large building supply company-.docx
 
John has tremendous technical skills and frequently comes up with valu.docx
John has tremendous technical skills and frequently comes up with valu.docxJohn has tremendous technical skills and frequently comes up with valu.docx
John has tremendous technical skills and frequently comes up with valu.docx
 
Joe Frecaso was recently hired as the controller for Larson Cement Com.docx
Joe Frecaso was recently hired as the controller for Larson Cement Com.docxJoe Frecaso was recently hired as the controller for Larson Cement Com.docx
Joe Frecaso was recently hired as the controller for Larson Cement Com.docx
 
Java Write a method that takes as a parameter a one dimensional array.docx
Java Write a method that takes as a parameter a one dimensional array.docxJava Write a method that takes as a parameter a one dimensional array.docx
Java Write a method that takes as a parameter a one dimensional array.docx
 
Java Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docxJava Programming- 1) Write a recursive method that finds and returns t.docx
Java Programming- 1) Write a recursive method that finds and returns t.docx
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
 
Java Language Which of the following statements is true- Select all th.docx
Java Language Which of the following statements is true- Select all th.docxJava Language Which of the following statements is true- Select all th.docx
Java Language Which of the following statements is true- Select all th.docx
 
It-'s virtualization topic Would anyone please expalin what is the di.docx
It-'s virtualization topic  Would anyone please expalin what is the di.docxIt-'s virtualization topic  Would anyone please expalin what is the di.docx
It-'s virtualization topic Would anyone please expalin what is the di.docx
 
For each pair of substance identify the substance that is likely to ha.docx
For each pair of substance identify the substance that is likely to ha.docxFor each pair of substance identify the substance that is likely to ha.docx
For each pair of substance identify the substance that is likely to ha.docx
 
For each of the requirements listed in the table below- 1- Please iden.docx
For each of the requirements listed in the table below- 1- Please iden.docxFor each of the requirements listed in the table below- 1- Please iden.docx
For each of the requirements listed in the table below- 1- Please iden.docx
 
For Contingent Liability- When do you disclose it- When do you record.docx
For Contingent Liability- When do you disclose it- When do you record.docxFor Contingent Liability- When do you disclose it- When do you record.docx
For Contingent Liability- When do you disclose it- When do you record.docx
 
For each of the abstract data types (ADTs) that we have analyzed in th.docx
For each of the abstract data types (ADTs) that we have analyzed in th.docxFor each of the abstract data types (ADTs) that we have analyzed in th.docx
For each of the abstract data types (ADTs) that we have analyzed in th.docx
 
For each form of transport plot the value of overall benefits against.docx
For each form of transport plot the value of overall benefits against.docxFor each form of transport plot the value of overall benefits against.docx
For each form of transport plot the value of overall benefits against.docx
 
Fluid Mechanics The water surface is at the position shown at t - 0 se.docx
Fluid Mechanics The water surface is at the position shown at t - 0 se.docxFluid Mechanics The water surface is at the position shown at t - 0 se.docx
Fluid Mechanics The water surface is at the position shown at t - 0 se.docx
 
Fluctuation in inflation can occur in the short or long term- For exam.docx
Fluctuation in inflation can occur in the short or long term- For exam.docxFluctuation in inflation can occur in the short or long term- For exam.docx
Fluctuation in inflation can occur in the short or long term- For exam.docx
 
First National Bank charges 11-2 percent compounded monthly on its bus (1).docx
First National Bank charges 11-2 percent compounded monthly on its bus (1).docxFirst National Bank charges 11-2 percent compounded monthly on its bus (1).docx
First National Bank charges 11-2 percent compounded monthly on its bus (1).docx
 

KĂĽrzlich hochgeladen

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...Pooja Nehwal
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 

KĂĽrzlich hochgeladen (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
CĂłdigo Creativo y Arte de Software | Unidad 1
CĂłdigo Creativo y Arte de Software | Unidad 1CĂłdigo Creativo y Arte de Software | Unidad 1
CĂłdigo Creativo y Arte de Software | Unidad 1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 

It is proposed to caluculate pi by using the Monte Carlo method- A cir.docx

  • 1. It is proposed to caluculate pi by using the Monte Carlo method. A circle of radius 1 is inside a square of side 2. We count how many of m random points in the square happen to lie in the circle. Assume that the error is 1/square root m. How many points must be taken to obtain pi with three accurate figures? Write a program to find the answer. Solution /* Program to compute Pi using Monte Carlo methods */ #include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> #define SEED 35791246 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;
  • 2. printf("# of trials= %d , estimate of pi is %g ",niter,pi); }