
Patrick B. answered 10/06/19
Math and computer tutor/teacher
Well, as you suggested, the quick and dirty way would be to
#define PI (22.0/7)
Here is an algorithm for approximating it numerically....
STEP 1: Start with the unit circle centered at the origin : x^2 + y^2 = 1
STEP 2: INSCRIBE this unit circle firmly and snugly inside a square with side measure 2.
The vertices of this square are then (-1,1), (1,1), (1, -1) and (-1,-1)
STEP 3: Choose a very large number for N, like N=100000 or even 1 million
STEP 4: Generate N order pairs inside this square: -1 <= x <= 1 and -1 <= y < = 1
STEP 5: for each order pair... count how many are INSIDE or ON the circle.
T = # of ordered pairs inside or ON the circle
STEP 6: pi = 4*T/N
Proof:
The radius of the circle is 1. So the area of the circle inside the square is just PI.
Meanwhile, the area of the square is 4. So the ratio of the areas of circle to square is PI/4