Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   General formula for Code (http://www.go4expert.com/forums/formula-code-t23888/)

eblack10 17Nov2010 02:19

General formula for Code
 
C code
Code:

int f(int n)
{
return(0);
if(n==1)
return(1);
printf("ADD");
return(f(n-1)+f(n-2));
}

What general formula can you derive from this if someone was to use f(n)?

ihatec 17Nov2010 03:30

Re: General formula for Code
 
Sorry but your code will stop execution at first line, but I suppose you want to obtain recursive algorithm for n-th Fibbonacci number.

eblack10 17Nov2010 20:56

Re: General formula for Code
 
That is what I thought. I was argued down that it should compile. Thanks!

jimblumberg 19Nov2010 01:18

Re: General formula for Code
 
Quote:

Originally Posted by eblack10 (Post 74810)
That is what I thought. I was argued down that it should compile. Thanks!

It will compile, but should have a warning about unreachable code.

Jim


All times are GMT +5.5. The time now is 16:54.