CS19002 Programming and Data Structures Laboratory Spring 2009, Section 2

Assignment 2
(Loops)

Part 1   [Credit: 70%]

In this assignment, you are asked to find the real root of f(x) = x3+123x2+5678x+97531 by the method of successive bisection. Start with the lower bound l = -100 and with the upper bound u = +100. We have f(l) < 0 and f(u) > 0, that is, a root of f(x) lies between -100 and +100. Write a loop each iteration of which computes the center x of the current interval [l,u], evaluates f() at x, and, based upon the sign of f(x), modifies the search interval to [l,x] or [x,u]. The loop terminates when the interval becomes narrower that 10-10.

Print the root x of f(x) found in the above loop.

Part 2   [Credit: 30%]

Print the root x in hexadecimal. You must not use any built-in routine for printing a floating point number in hexadecimal (like %a). You may, however, print an integer in hexadecimal by the %x directive. Multiply the fractional part successively by 16 in order to extract the hexadecimal digits of the fraction.

Submission site | Lab home | Course home | My home