H6-sol - Solutions of Homework 6 Programming Project • The following is the complete C program that implements the given function with the

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 University-West Lafayette.

Page1 / 3

H6-sol - Solutions of Homework 6 Programming Project • The following is the complete C program that implements the given function with the

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online