fibonacci number
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 12 of 12

Thread: fibonacci number

Threaded View

  1. #1
    Join Date
    Feb 2014

    fibonacci number

    Hi, the next code is right. I mean it works. It gives the sequence of fibonaci numbers ...

    #include <iostream>
    #include <iomanip>
    using namespace std;
    int fibo(int pos)
      if(!pos)return 0;
      if(pos==1)return 1;
      int pos2=--pos;
      int pos1=--pos;
      int r1=fibo(pos1);
      int r2=fibo(pos2);
      int r=r1+r2;
      return r;
    int main()
      int number;
      for(int p=0;p<number;++p)
          int r=fibo(p);
          cout<<p<<"  "<<r<<endl;
      return  0;
    when I chage the lines:
    int r1=fibo(pos1);
      int r2=fibo(pos2);
      int r=r1+r2;
    for the lines:

    int r=fibo(pos1)+fibo(pos2);
    It doen't work right. Apararently it should work the same.
    Can anyone give an explanation to this...?????

    Last edited by Jose M; February 16th, 2014 at 05:01 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center