Submit your assignment including your code through myCourses.
- (5 points) Write a C program to find the smallest positive integer x such that the floating point expression
1 (1 x)
is not equal to x, using single precision. Make sure that the variable x has type float, and assign the value of the expression 1 x to a float variable before doing the other division operation. Repeat with double precision.
- (5 points) A calculus student was asked to determine limn xn, where xn = (100n)/n!. He wrote a C program in single precision to evaluate xn by using
x1 = 100, xn = 100xn1/n, n = 2,3,,70.
The numbers printed became ever larger and finally became . So the student concluded that limn xn = . Please write a C program in single precision to verify the students observation. The students conclusion is actually wrong. What is the problem with his program?
Bonus (2 points): Can you rewrite a C program to evaluate xn so that you can make a right conclusion about limn xn ?
- (10 points) In 250 B.C.E., the Greek mathematician Archimedes estimated the number as follows. He looked as a circle with diameter 1, hence circumference . Inside the circle he inscribed a square; see the following figure. The perimeter of the square is smaller than the
circumference of the circle, and so it is a lower bound for . Archimedes then considered an inscribed octagon, 16-gon, etc., each time doubling the number of sides of the inscribed polygon, and producing ever better estimates for . Using 96-sided inscribed and circumscribed polygons, he was able to show that 223/71 < < 22/7. There is a recursive formula for these estimates. Let pn be the perimeter of the inscribed polygon with 2n sides. Then p2 is the perimeter of the inscribed square, p2 = 22. In general
.
- Write a program to compute pn for n = 3,4,,35 in double precision by using the formula. Explain your results.
- Improve the formula to avoid the difficulty with it. Compute pn for n = 3,4,,35 by your new formula in double precision. Comment on your results.
Note: Your program should not do unnecessary computation.
Reviews
There are no reviews yet.