Write a program in C++ to display the first n terms of Fibonacci series

.#include <iostream>
using namespace std;
void main()
{
     int prv=0,pre=1,trm,i,n;
   cout<<"Input number of terms to  display : ";
   cin>>n;
   cout<<"Here is the Fibonacci series upto  to  : "<<n;
   cout<<"    " <<prv<<pre;

  for(i=3;i<=n;i++)
   {
     trm=prv+pre;
     cout<<"     "<<trm;
     prv=pre;
     pre=trm;
   }
   cout<<"\n";

      system ("pause");
}

Fibonacci series 0 1 2 3 5 8 13 .....
Test Data : 
Input number of terms to display : 10 
Expected Output :
Here is the Fibonacci series upto to 10 terms : 
0 1 1 2 3 5 8 13 21 34 

Write a program in C++ to display the first n terms of Fibonacci series Write a program in C++ to display the first n terms of Fibonacci series Reviewed by Unknown on May 30, 2017 Rating: 5

No comments:

Powered by Blogger.