Code Snippets

  

C++ Source Code


Welcome to Dream.In.Code
Become a C++ Expert!

Join 148,909 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,361 people online right now. Registration is fast and FREE... Join Now!





Recursive Fibonacci Sequence

This code shows how to generate a Fibonacci Sequence using Recursion.

Submitted By: born2c0de
Actions:
Rating:
Views: 42,138

Language: C++

Last Modified: March 2, 2005

Snippet


  1. long fib(unsigned long n) {
  2.     if (n <= 1) {
  3.         return n;
  4.     } else {
  5.         return fib(n-1)+fib(n-2);
  6.     }
  7. }

Copy & Paste


Comments


mahir 2007-11-15 07:47:24

where is header file

born2c0de 2008-01-18 04:00:07

This function does not require a header file. Besides, it is a code snippet and not a complete application. You will have to call it from main() or any other function to use it.

giotto 2008-02-04 08:59:49

Oh, come on! It can be done, in one line! int fibonacci(int number){ return number

giotto 2008-02-04 09:00:20

int fibonacci(int number){ return number

giotto 2008-02-04 09:00:49

:S

nurboja 2008-05-03 03:07:39

int fib(int x) { if (x==0) return 0; else if (x==1) return 1; else return fib(x-1)+fib(x-2); }

nurboja 2008-05-03 03:08:04

Fn=0 za n= 0; Fn=1 za n= 1; Fn=Fn–1+ Fn–2 za n>=2;


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month