Comment on Tutorial - C++ Recursion function explained using Fibonacci series By Emiley J



Comment Added by : nadia

Comment Added at : 2010-10-04 21:48:04

Comment on Tutorial : C++ Recursion function explained using Fibonacci series By Emiley J
how about this?...
#include<iostream.h>

int fibonacci(int n);

int main()
{

int number;

cout <<"Enter an integer :";
cin >> number;

for(int i=0;i<=number;i++)
{
cout <<fibonacci(i) <<" ";
}

cout << endl << endl;
for(i=0;i<=number;i++){
cout <<"Fibonacci "<< i <<" is "<< fibonacci(i) <<endl;

}
return 0;
}

int fibonacci(int n) {
if (n <= 1) {
return n;
} else {
return fibonacci(n-1)+fibonacci(n-2);
}
}


View Tutorial



Ask a Question

Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Hi,
I am using Nokia 3110c connected to PC.

View Tutorial          By: Satish Raj at 2009-04-04 07:32:54

2. This works great, just remember to add <uses-pe
View Tutorial          By: Nick at 2012-06-20 07:37:15

3. i need to use sms and to creat using java so it is
View Tutorial          By: Abdulkerim at 2009-09-07 05:29:15

4. hai i have downloaded the above sms source code i
View Tutorial          By: arunram at 2009-10-28 01:42:51

5. Nice Example...!
View Tutorial          By: Kuldeep Singh at 2009-10-18 23:58:17

6. But the above code is not working, when we send SM
View Tutorial          By: SenthilPandi ChandraSekaran at 2011-06-08 07:22:31

7. super
View Tutorial          By: chalamareddy at 2012-10-08 18:08:29

8. i have an exception unknown host.
please te

View Tutorial          By: saddam hussain at 2011-03-22 10:46:48

9. document.loginform.userName.focus();
return

View Tutorial          By: Parthiban at 2014-07-21 08:03:00

10. this is really helpful example for Learning RMS in
View Tutorial          By: Ahmed Nawaz Mari at 2011-06-30 05:29:18