C++ Program for solving Fibonacci Series

Write a program in C++ language that gives Fibonacci series to Nth term with 

simple method using any kind of loop


****************************************************************************************************************************************************************************************************************


#include <iostream>

using namespace std;

 

int main() {

               

int n;

int t1 = 0;

int t2 = 1;

int nextTerm = 0;

 

cout <<"Enter the number of terms: "<<endl;

cin >> n;

 

cout <<"|| FIBONACCI SERIES ||"<<endl<<endl;

 

for (int i = 1; i <= n; ++i) {

 

if(i == 1) {

cout << t1 <<" + ";       // Prints the first terms.

}

 

if(i == 2) {

cout << t2 ;             // Prints the Second terms.

}

 

if(i>2){

        nextTerm = t1 + t2;

        cout <<" + "<< nextTerm ;

 

        t1 = t2;

        t2 = nextTerm;

}

}

        cout<<endl<<endl;           //for next line .

       

return 0;

}


****************************************************************************************************************************************************************************************************************


OUTPUT:




NOTE:  Programming Fundamental In BsCs 

Comments