Fibbonaci series program

Showing Answers 1 - 17 of 17 Answers

pitamber kumar

  • Aug 14th, 2006
 


#include <iostream>

using namespace std;
int main ()
{
int fOne = 1;
int fTwo = 1;
int fThree = 2;
long fN;
long fNN;

cout << "How many n terms do you want in the sequence: ";
cin >> fN;

for ( fN = 1 ; fN >= 3 ; fN++ )
{
for (fNN = 1; fNN >= fN; fNN++)
fNN = (fN - 1) + (fN - 2);
cout << fN;

  Was this answer useful?  Yes

jay

  • Sep 23rd, 2006
 

since this is a C interview question column, please avoid namespaces and native c++ constructs.anyways, I gather the most elegant solution to be the recursive way : #include int fibonacci(int n) { if (n <= 1) return n; else return fibonacci(n-1) + fibonacci(n-2);}#define FIBs 20int main(int argc, char *argv[]){ for(int i=0; i < FIBs ; i++) printf("%d'th : %d",i,fibonacci(i));}

  Was this answer useful?  Yes

Raju Tewari

  • Nov 20th, 2006
 

Int fibbonaci(){if(n==1|| n==2){return 1;elsereturn(fibbonaci(n-1)+fibbonaci(n-2));}void main(){int i,n;int a[3]={0,1};for(i=2;i

  Was this answer useful?  Yes

Deepak

  • Jan 24th, 2007
 

A simple and logical solution to this problem is as follows :-int fib(int pos){return (pos > 2)? fib( pos - 1) + fib(pos - 2) : (pos == 1)? 0:1; }This function will return the 'pos' value of fibbonaci series...call this function proper number of times to generate particular length fibbonaci series.

  Was this answer useful?  Yes

jintojos

  • May 24th, 2008
 

// Fibnocci Series Using Recursion #include #include void fun(int,int); int num; void main() { clrscr(); printf("Enter The Limit :"); scanf("%d",&num); printf("The Fibnocci Series Up To %d Is......nnt 0",num); fun(0,1); getch(); } void fun(int a,int b) { if(b>num) return; printf(" %d",b); fun(b,a+b); }

  Was this answer useful?  Yes

jintojos

  • May 24th, 2008
 

 // Fibnocci Series Using Recursion

  #include<stdio.h>
  #include<conio.h>
  void fun(int,int);
  int num;
  void main()
    {
 clrscr();
 printf("Enter The Limit :");
 scanf("%d",&num);
 printf("The Fibnocci Series Up To %d Is......nnt 0",num);
 fun(0,1);
 getch();
    }

  void fun(int a,int b)
    {
       if(b>num) return;
       printf(" %d",b);
       fun(b,a+b);
    }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions