Write C code that does the following:
1. Numerically compute the following series
1−
1
3
+
1
5
−
1
7
+
1
9
− … =
π
4
,
and approximate π (details in class). Vary iteration
numbers and find out how many terms are needed to get 3.14159.
Background.
Note that the general term, an, is expressed as
an =
(−1)n+1
2 n − 1
.
2.
A sequence an is given with the following rule:
an+2 = − 2 an+1 + 3 an, a0 = 2, a1 = −1.
Write a C program to compute a17.
3. (a) Write a function, int factorial(int n), which returns
n! (the factorial of n, i.e. 1 ×2 ×3 ×…×n.)
(b) Using int factorial(int n) above, write a program to compute
1 +
1
1!
+
1
2!
+ …+
1
11!
.
Make sure that you
attach example runs showing the results from the computer.
File translated from
TEX
by
TTH,
version 4.03. On 09 Jun 2025, 15:22.