can be approximated by using the following inte series ++) White a program that points out two versions of the approximation one that goes out to a denominator of 13 and one that goes out of a denominator of 18 Note you will want to use 1.0 for your numerators. In my code used a decimal version for all of these inters
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
1. Start
2. Define a class PiApproximation:
a. Define a method calculatePiApproximation(denominator):
i. Initialize piApproximation to 0.
ii. Initialize a boolean variable subtract to false.
iii. Iterate i from 1 to denominator with a step of 2:,a. Define a method calculatePiApproximation(denominator):
i. Initialize piApproximation to 0.
ii. Initialize a boolean variable subtract to false.
iii. Iterate i from 1 to denominator with a step of 2:,a. Define a method calculatePiApproximation(denominator):
i. Initialize piApproximation to 0.
ii. Initialize a boolean variable subtract to false.
iii. Iterate i from 1 to denominator with a step of 2:,a. Define a method calculatePiApproximation(denominator):
i. Initialize piApproximation to 0.
ii. Initialize a boolean variable subtract to false.
iii. Iterate i from 1 to denominator with a step of 2:
a. If subtract is true:
- Subtract 1.0 divided by i from piApproximation.
b. Else:
- Add 1.0 divided by i to piApproximation.
c. Toggle the value of subtract.
iv. Return 4*piApproximation.
b. Define the main method:
i. Calculate pi approximation with denominator 13 using calculatePiApproximation(13).
ii. Print "Approximation of pi with denominator 13: " concatenated with the calculated value.
iii. Calculate pi approximation with denominator 15 using calculatePiApproximation(15).
iv. Print "Approximation of pi with denominator 15: " concatenated with the calculated value.
3. End
Step by step
Solved in 4 steps with 2 images