CS13002 Programming and Data Structures

(Autumn semester)    Section A

Assignment Set - 5

Please write your Roll Number, Name and Assignment Number at the header of each program.


Assignment 5.a:        Filename: a5a.c

Rewrite the program for finding roots (Assignment 1.b) using two functions:

(a)    A function that returns the value of f(x) for a given value of x, where:

        f(x) = ( x2 - 10x + 16 )( log4 x - 2 )

       You had written this function in Assignment 3.a

(b)    A recursive function: findroot( low, high, precision ) which returns a root between low and high.

The recursive function uses the bisection method recursively to refine low or high at each level of recursion.
The recursion stops when
|high - low| < precision

To copy the file a3a.c to a5a.c use the command cp a3a.c a5a.c from the command prompt.


Assignment 5.b:        Filename: a5b.c

Write a recursive function, ipow(x, n), to return x to the power of n, where n is a non-negative integer, using repeated squaring, that is:

x2n = (xn) × (xn)      and       x2n+1 = x × x2n.

Write a main program that reads a floating point number, x, and an integer, n, and calls the function to return and print the nth power of x. Also use a global variable, cnt, to count the number of multiplications performed.


Course home