-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci.cpp
More file actions
55 lines (40 loc) · 945 Bytes
/
fibonacci.cpp
File metadata and controls
55 lines (40 loc) · 945 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Fibonacci number
Description
In mathematics, the Fibonacci numbers, commonly denoted Fₙ, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1.
*/
#include<iostream>
using namespace std;
void fibbo(int n)
{
int a=0,b=1,c;
int i=2;
cout<<" "<<a<<" "<<b;
while(i!=n)
{
c=a+b;
cout<<" "<<c;
a=b;
b=c;
i++;
}
}
int main()
{
int n;
cout<<"\n Fibonacci series\n";
cout<<"\n Enter the number of terms : ";
cin>>n;
cout<<"\n "<<n<<" terms of fibbonacci series are : ";
fibbo(n);
cout<<"\n";
return 0;
}
/* Output
(base) mansi@mansi-Vostro-15-3568:~$ g++ fibonacci.cpp
(base) mansi@mansi-Vostro-15-3568:~$ ./a.out
Fibonacci series
Enter the number of terms : 20
20 terms of fibbonacci series are : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
(base) mansi@mansi-Vostro-15-3568:~$ ^C
*/