#include <iostream>
using namespace std;
int main()
{
int Nth_term, counter =
2, new_term = 1, prev_term = 1, term_before_prev = 0;
cout
<< "Enter the number of term to which you want to print
the Fibonacci Sequence: ";
cin
>> Nth_term;
if (Nth_term != 0)
cout
<< new_term << endl;
for (counter = 2;
counter <= Nth_term; counter++){
new_term
= prev_term + term_before_prev;
cout
<< new_term << endl;
term_before_prev
= prev_term;
prev_term
= new_term;
}
return 0;
}
No comments
Post a Comment