Description
The number π is known to be an irrational number and cannot be expressed exactly in decimal
format. The decimal value, however, can be approximated. Many approximation formulae have been
developed. One of them is shown below.
π − 3
4
=
1
2 · 3 · 4
−
1
4 · 5 · 6
+
1
6 · 7 · 8
−
1
8 · 9 · 10
+
1
10 · 11 · 12
−
1
12 · 13 · 14
+ . . . (2.1)
Though not the most accurate, we assume the value of π can be calculated using the 6-term series on the
right hand side.
The trigonometric function sin(x) can also be approximated using infinite series as shown below.
sin(x) = ∑∞
k=1
(−1)k−1x
k
k!
(2.2)
= x −
x
3
3! +
x
5
5! −
x
7
7! + . . . (2.3)
For this lab, we assume sin(x) can be approximate accurately using 4-term series as above.
In this lab, please write a C program to find the value of π and sin(
π
6
). The output of the program
should be as following:
$ ./a.out
pi = x.xxxxx
sin(pi/6) = x.xxxxxx
Notes.
1. Create a directory lab02 and use it as the working directory.
2. Name your program source file as lab02.c.
3. The first few lines of your program should be comments as the following.
/* EE231002 Lab02. PI and sine function
ID, Name
Date:
*/
4. After finishing editing your source file, you can execute the following command to compile it,
$ gcc lab02.c
If no compilation errors, the executable file, a.out, should be generated, and you can execute it by
typing
$ ./a.out
5. After you finish verifying your program, you can submit your source code by
$ ∼ee231002/bin/submit lab02 lab02.c
If you see a ”submitted successfully” message, then you are done. In case you want to check which
1
file and at what time you submitted your labs, you can type in the following command:
$ ∼ee231002/bin/subrec
It will show the last few submission records.
6. Since loops have not been covered yet, do not use loops in this lab. And because no loops, program
efficiency is not the best. Thus, for this lab only, the efficiency is not emphasized.
2