xt can be approximated by using the following infinite serios, x=4 3 1 5 1 7 1 4- 9 11 Write a program that prints out two versions of the approximation one that goes out to a denominator of 13 and one that goes out of a denominator of Note you will want to use 1.0 for your numerators. In my code I used a decimal version for all of these integers.
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
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. If subtract is true:
- Subtract 4.0 divided by i from piApproximation.
b. Else:
- Add 4.0 divided by i to piApproximation.
c. Toggle the value of subtract.
iv. Return 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