--%>

Write a program and estimate pi using 400, 4000, 40000, 4000

Consider a dartboard of radius 1. Since the area of the board will be  π r2 = π * 1 *1, it's clear the area of the dartboard is exactly π. The area of a square surrounding the board (circumscribing it) would be 2*2 = 4, since the diameter or the dartboard is 2 (twice the radius) and the diameter equals length of a side of the square. Now, if we introduce a set of darts, where the x and y range from -1 to +1, we simulate a random sampling of all positions on the square surrounding the dartboard, some on the board and some of the square surrounding it. You can determine whether the dart hit the board or not by simply calculating if its distance from the center of the dartboard is greater than 1 (off the board) or <=1 (on the board). If we toss 4 darts, corresponding to area of the square, we will expect π darts, on average, to hit inside the dartboard and the remainder to miss. By extension, if we toss 40000 darts, 10000*π  should hit the dartboard. We can use this largest set to give us a decent estimation.

 

   Related Questions in Programming Languages

  • Q : Define PS3 Debug/TEST/Prototype

    Define PS3 Debug/TEST/Prototype Consoleroduction deployment.

  • Q : Basic features of OOPs Illustrate the

    Illustrate the basic features of OOPs?

  • Q : Does TestComplete maintain testing of

    Does TestComplete maintain testing of Flex applications?

  • Q : How is an XPointer processor configured

    How is an XPointer processor configured?

  • Q : State Cout and Cin Cout: This is an

    Cout: This is an object of ostream_withassign class stated in iostream.h header file

  • Q : Define the term Interface inheritance

    Interface inheritance: Whenever a class implements an interface, the interface inheritance relationship exists among them. The class inherits no implementation from interface, just method signatures and static variables. It is as well possible for one

  • Q : What is Timeslice Timeslice : It is the

    Timeslice: It is the amount of running time assigned to a process or thread prior to the scheduler considers the other to be run. The process or thread will not be capable to employ its full allocation of time when it becomes blocked or preempted thro

  • Q : Write a program using simple loop

    Objective:  The purpose of this problem is to gain experience with the principles necessary to write a program using simple loop, decision processing, counters and accumulators Save the Barns, a bi-partisan po

  • Q : What is an Anonymous array Anonymous

    Anonymous array: It is an array formed without an identifier. The anonymous array is generally formed as an actual argument, for example:// generate an anonymous array of integers.    YearlyRainfall y2k = new YearlyRai

  • Q : What is Left shift operator Left shift

    Left shift operator: Left shift operator (<<) is the bit manipulation operator. This moves the bits in its left operand zero or additional positions to the left, according to the value of its right operand. The zero bits are added up to the righ