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 Constant Constant : It is the

    Constant: It is the memory block where value can be stored once although can’t modify later on throughout program execution. Example: const int pi =3.14;

  • Q : Define Object-oriented language

    Object-oriented language: Programming languages like Java and C++ which permit the solution to a trouble to be stated in terms of objects that belong to the classes.

  • Q : Business Process Management Describe

    Describe what is Business Process Management (or BPM) in brief.

  • Q : Installation of Symbian SIS file to

    I am not capable to install Symbian SIS file to Symbian OS v.9.x tool? What must I do?

  • Q : What is Static initializer Static

    Static initializer: An initializer prefixed with ‘static’ reserved word. The static initializer is stated outside the methods of its enclosing class, and might access only the static fields and methods of its enclosing class.

  • Q : Properties exposed through ActiveX

    Write down the properties exposed through ActiveX controls?

  • Q : What is Cursor Cursor : This is a

    Cursor: This is a visual representation of the existing position of the mouse on the user's virtual desktop. Cursor shapes are frequently set to symbolize the current state of a program – utilizing an hour glass shape to point out that the user

  • Q : Define the way to threads own the mutex

    Define the way to threads own the mutex?

  • Q : Define Class inheritance Class

    Class inheritance: Whenever a super class is expanded through a sub class, a class inheritance relationship exists among them. The sub class inherits the attributes and methods of its super class. Class inheritance in Java, is single

  • Q : Functions of states of the

    Mention the different states of the XMLHttpRequest an dalso describe their functions.

©TutorsGlobe All rights reserved 2022-2023.