- الكود:
#include <iostream>
using namespace std;
int main()
{
long long n, t1 = 0, t2 = 1, nextTerm = 0,s1 = 0, s2 = 1, ss = 0;
cin >> n;
if (n==0)
cout<<0<<" "<<1;
else
{
for (int i = 1; i <= (n+1); ++i)
{
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
if (i==(n+1))
cout << nextTerm-1 << " ";
}
for (int i = 1; i <= (n); ++i)
{
ss = s1 + s2;
s1 = s2;
s2 = ss;
if (i==(n))
cout << ss+(nextTerm-1) << " ";
}
}
return 0;
}
ALL | FFFFFFFFFF | MMMMMMMMM | YEARS |
4 | 2 | 2 | 2 |
7 | 3 | 4 | 3 |
12 | 5 | 7 | 4 |
20 | 8 | 12 | 5 |
33 | 13 | 20 | 6 |
54 | 21 | 33 | 7 |
88 | 34 | 54 | 8 |
143 | 55 | 88 | 9 |
232 | 89 | 143 | 10 |
https://en.wikipedia.org/wiki/Fibonacci_number
https://www.programiz.com/cpp-programming/examples/fibonacci-series