Computer Science, asked by ABAbhishek171, 11 months ago

Wap to generate fibonacci series upto user define limit in c++_

Answers

Answered by sswaraj04
0

Answer:

#include <iostream>

using namespace std;

int main()

{

   int n, t1 = 0, t2 = 1, next = 0;

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

   cin >> n;

   cout << "Fibonacci Series: ";

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

   {

       if(i == 1)

       {

           cout << " " << t1;

           continue;

       }

       if(i == 2)

       {

           cout << t2 << " ";

           continue;

       }

       next = t1 + t2;

       t1 = t2;

       t2 = next;

       

       cout << next << " ";

   }

   return 0;

}

Explanation:

Answered by rakeshchennupati143
0

Program:

#include<iostream>

using namespace std;

main(){

     int n, i, first = 0, second = 1, next;

     cout << "Enter the nth term" << endl;

     cin >> n;

     cout << "First " << n << " terms of Fibonacci series are :- " << endl;

     for ( i= 0 ; i< n ; i++ ){

           if ( i<= 1 )

                 next = i;

           else{

                 next = first + second;

                 first = second;

                 second = next;

           }

           cout << next<<" "<< endl;

     }

     return 0;

}

Output:

Enter the nth term : 10

First 10 terms of fibonacci series are :

0 1 1 2 3 5 8 13 21 34

----Hope you got what you wanted mark as brainliest if you liked my asnwer

      :)

Similar questions