96
edits
Changes
→Calculation of Pi
==== Calculation of Pi ====
For this assessment, I used code found at [https://helloacm.com/cc-coding-exercise-finding-approximation-of-pi-using-monto-carlo-algorithm/ helloacm.com]
In this version, the value of PI is calculated using the Monte Carlo method.
This method states:
# A circle with radius '''r''' in a squre with side length '''2''r'''''
# The area of the circle is '''Πr<sup>2</sup>''' and the area of the square is '''4r<sup>2</sup>'''
# The ratio of the area of the circle to the area of the square is: '''Πr<sup>2</sup> / 4r<sup>2</sup> = Π / 4'''
# If you randomly generate '''N''' points inside the square, approximately '''N * Π / 4''' of those points ('''M''') should fall inside the circle.
# '''Π''' is then approximated as:
::* '''N * Π / 4 = M '''
::* '''Π / 4 = M / N'''
::* '''Π = 4 * M / N'''
For simplicity the radius of the circle is 1.
With this, we randomly generate points within the area and count the number of times each point falls within the circle, between 0 and 1. We then calculate the ratio and
multiply by 4 which will give us the approximation of Π.
=== Assignment 2 ===
=== Assignment 3 ===