hi there, i also have an emergency home work

it about Fibonnaci recursive

the Output is should be like this :
--------------------------------------------------
First number of the fibonnaci : 3

The Fibonacci Lines are : 3 4 7 11 18 29 ...
----------------------------------------------------

i want the result is until 10 lines

i try all i do to finish this task, but always failed.

can anyone help me?

Recommended Answers

make a new post and don't hijack another person's thread... read the forum rules. also before you post that question, you need to make an attempt at completing it first.

Jump to Post

use
fibonaci(int n)
{
if(n==1) return o;
if(n==2) return 1;
return fibonaci(n-1)+fibonaci(n-2);
}

I think you need to read these:

http://www.daniweb.com/techtalkforums/announcement8-2.html

Jump to Post

how this function is used. i m so confused n not getting the proper result

Fibonacci number is calculated in pretty straightfoward way:
[IMG]http://upload.wikimedia.org/math/0/c/e/0cebc512d9a3ac497eda6f10203f792e.png[/IMG]
No additional comments needed...

Jump to Post

All 10 Replies

make a new post and don't hijack another person's thread... read the forum rules. also before you post that question, you need to make an attempt at completing it first.

use
fibonaci(int n)
{
if(n==1) return o;
if(n==2) return 1;
return fibonaci(n-1)+fibonaci(n-2);
}

hey,
i will like you to post the code you have written so that i can help with it... i have written it and it worked but i want to make sure you know it and not just copy mine... i will tell you where the mistakes are and where you should make ammendments.....
trust me

how to show this ?

Input number [1-40]: 3
3 first fibonacci : 1 1 2

i have no idea 'bout that...

void main()
{
int n,i,j,k,s;
printf("give your choice from 1-40")
scanf("%d",&n);
i=0,j=1;
if(n==1)
{
printf("%d",i);
break;
}
if(n==2)
{
printf("%d %d ",i,j);
break;
}
else
(
printf("%d %d ",i,j);
for(k=0;k<n-1<k++)//as two values have already written;
{
s=i+j;
i=j;
j=s;
printf(" %d",s);
}
}
}

how this function is used. i m so confused n not getting the proper result

How about this one?

Not bad for a basic attempt at iterative and recursive algorithms. Given that the complexity of the recursive fibonacci algorithm is horrendous, I'd also include a memoized version:

int Fibonacci_Recursion(int n)
{
    if (n < 1) {
        return 0;
    }
    else if (n < 3) {
        return 1;
    }
    else {
        int value = find(n);

        if (value != -1) {
            return value;
        }

        value = Fibonacci_Recursion(n - 1) + Fibonacci_Recursion(n - 2);
        save(n, value);

        return value;
    }
}

I especially enjoyed this comment: "I think implementation in recursion is better because it call itself recursively". It's a completely nonsensical and irrational reason for calling the recursive implementation "better", especially given that between the two I'd choose the iterative version 10 times out of 10 because it uses O(n) time and O(1) space. Even the memoized recursive version uses O(n) time and O(n) space, and it's more complex.

On a side note, you're allowed to use the space bar. Coding in C isn't a contest to see who can write the most compact tokens, and judicious whitespace will make your code much easier to read.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.