RED LIZZRD

Program to print “Fibonacci series” up to n.

It is a series starting from 0 or sometimes from 1 whose subsequent number is the sum of the previous two numbers.                                                                                              Example :-
011235813213455891442333776109871597258441816765………
Source code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include<conio.h>
#include<iomanip>
 
using namespace std;
 
int main()
{
    long int i,f1=0,f2=1,f3,number;
    cout<<"Enter number :";cin>>number;cout<<endl;
    if(number>=1)
        cout<<"0"<<endl;
    if(number>=2)
        cout<<"1"<<endl;
 
    for(i=3;i<=number;i++)
    {
        f3=f1+f2;
        cout<<f3<<endl;
        f1=f2;
        f2=f3;
    }
    getch();
}
 

Unknown

Unknown

Related Posts:

No comments :

Post a Comment

Powered by Blogger.