C progam

Closed
saqi - Nov 5, 2009 at 11:47 PM
 Blocked Profile - Nov 6, 2009 at 02:12 AM
Hello,
how to make a fibonacci series

1 reply

Blocked Profile
Nov 6, 2009 at 02:12 AM
Dear Saqi,

Please consider going through the following sample and

hence have the solution of your problem.

#include<iostream>
using namespace std;
int fibonacci(int n)
{
int x1 = 0, fib;
int x2 = 1;
if(n >= 1)
{
for(int i=2;i<= n; i++)
{
fib = x1+ x2;
x1 = x2;
x2 = fib;
}}
return fib;
}
int main(){
for(int i=2;i<=10;i++) {
cout<<fibonacci(i)<<endl;
}
return 0;
}

Hope that the information provided proves useful to you.

Thank you.
0