Wednesday, 25 May 2016

FIBONACCI SERIES - HSC FAVORITE QUESTION

NOW WHAT IS FIBONACCI SERIES....

0,1,1,2,3,5,8,13........

followed the trend???Noo??

A series of number in which each number is the sum of preceding two numbers is known as Fibonacci series.
This is a very important and the most asked question of HSC.


#include<iostream.h>

#include<conio.h>



void main()

{

clrscr(); \\clears the previous output



int a=0, b=1, n, c;  \\first two numbers of fibonacci series is 0 and 1

cout<<"Enter the number of terms till you want fibonacci series";

cin>>n; \\User choice, till wherever he wants to print the series

cout<<a<<"\t"<<b;



for(int i=1; i<=(n-2);i++)           \\ you must be thinking why (n-2), its because first two terms i.e 0                                                            and 1  are already included

{

cout<<a<<"\t"<<b<<"\t";       \\it'll print 0 and 1 which is first two numbers

c=a+b;                \\now as we go by definition fibonacci series is evaluated by adding the
                                                                                        previous two numbers....here that number is c

cout<<c;

b=c; \\now upgrade the values of variable.... think yourself y

a=b;

}

getch();

}




No comments:

Post a Comment