Jump to content

Young–Fibonacci lattice

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Tungsten Tide

Tungsten Tide

    Newbie

  • Members
  • Pip
  • 2 posts
Hi everybody. I was coding a simple way to do a infinite add table.
There's what i got so far. Any input ideas to make it in a class would be helpful.
#include <cstdio>

using namespace std;
int fib (int);

int main (int argc,char* argv[])
{
    printf("What fibonacci range from 0 to :");
    int n;
    scanf("%d",&n);

      for ( int k = 0 ; k < n; k++)
      {
      int i = fib(k);
      printf("%d\t",i);
      }
      return 0;
}

int fib (int n)
{
      for ( int i = 0; i <= -1; i++ )
      {
      if(i == 0)
      i = (fib(n - 1) + (fib(n - 2)));
      }
  return n;
}


#2
kmhosny

kmhosny

    Programmer

  • Members
  • PipPipPipPip
  • 133 posts
i am sorry but what do you mean by infinite add table, and i think the code you posted doesn't end since your loop i=0;i<=-1;i++ and the Fibonacci doesnt get negative numbers.
if what you need is only to make a class here you go
#include <cstdio>

using namespace std;
class Fibonacci
{
public:
    int fib (int n)
   {
         for ( int i = 0; i <= -1; i++ )
         {
         if( i == 0)
              i = (fib(n - 1) + (fib(n - 2)));
         }
         return n;
    }
};

int main (int argc,char* argv[])
{
    printf("What fibonacci range from 0 to :");
    int n;
    Fibonacci f;
    scanf("%d",&n);

      for ( int k = 0 ; k < n; k++)
      {
      int i = f.fib(k);
      printf("%d\t",i);
      }
      return 0;
}



"Recursion is just a line of code"
-Karim Hosny-
My flickr