CPP
using namespace std;
int main()
{
int a = 0, b = 1, NT = 0, n; // NT=Next Term
cout << "Enter a positive number : \n";
cin >> n;
// displays the first two terms which is always 0 and 1
cout << "Fibonacci Series is : " << a << ", " << b << ", ";
NT = a + b;
while(NT <= n)
{
cout << NT << ", ";
a = b;
b = NT;
NT = a + b;
}
return 0;
}
Fibonacci Series in C++
09 July
0
Write a program (WAP) in C++ to calculate Fibonacci Series of a numbers.
#include <iostream>using namespace std;
int main()
{
int a = 0, b = 1, NT = 0, n; // NT=Next Term
cout << "Enter a positive number : \n";
cin >> n;
// displays the first two terms which is always 0 and 1
cout << "Fibonacci Series is : " << a << ", " << b << ", ";
NT = a + b;
while(NT <= n)
{
cout << NT << ", ";
a = b;
b = NT;
NT = a + b;
}
return 0;
}
Out Put :-
Must Read :-
Previous article
Next article
Leave Comments
Post a Comment