A C++ program to generate Fibonacci series or sequence. While doing engineering many time ask the same question that how to write a program to generate Fibonacci series. Here is how you can achieve it.
Series is 1 1 2 3 5 8 13 21 34 55.............
Here is the code for Fibonacci sequence.
main()
{
clrscr();
int a,b,c;
a=1;
b=1;
c=0;
cout<<a;
cout<<endl<<b;
while (c<50)
{
c=a+b;
cout<<endl<<c;
a=b;
b=c;
}
getch();
}
Series is 1 1 2 3 5 8 13 21 34 55.............
Here is the code for Fibonacci sequence.
main()
{
clrscr();
int a,b,c;
a=1;
b=1;
c=0;
cout<<a;
cout<<endl<<b;
while (c<50)
{
c=a+b;
cout<<endl<<c;
a=b;
b=c;
}
getch();
}
No comments:
Post a Comment