This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Solutions of Homework 6 : Programming Project • The following is the complete C program that implements the given function with the required modifications. #include <math.h> #include <stdio.h> #include <stdlib.h> int count; double fun(double n){ count++; if (n<=2) return (1); else return (5+fun(pow(n,1.0/3.0))); } int main(){ int i; printf("n\t\tCount\t\tReturned Value\n"); printf("=====\t\t=====\t\t==============\n"); for (i=0; i<6; i++){ count = 0; printf("2^%3.0f\t\t%d\t\t%5.2f\n",pow(3,i),count,fun(pow(2.0,pow(3.0,i)))); } } • The output of the above program is: n Count Returned Value ===== ===== ============== 2^ 1 1 1.00 2^ 3 2 6.00 2^ 9 3 11.00 2^ 27 4 16.00 2^ 81 5 21.00 2^243 6 26.00 Note that running the program at n = 2 27 was not required in the project handout. 1 • To analytically find the Count , we establish the recurrence relation that describes the number of times, T ( n ), the function fun gets called and then solve it as follows: T ( n ) = 1 + T ( 3 √ n ) = 1 +...
View
Full
Document
This homework help was uploaded on 04/19/2008 for the course CS 182 taught by Professor W.szpankowski during the Fall '08 term at Purdue UniversityWest Lafayette.
 Fall '08
 W.Szpankowski

Click to edit the document details