Write a program in C++ to print Fibonacci series upto number entered by user

#include <iostream.h>
#include <conio.h>

int main() {   
   int n, c, first = 0, second = 1, next;
 
   cout<<"*** FIBONACCI SERIES ***"<<endl; 
   cout << "Enter number of terms: ";
   cin >> n;
   cout << endl;
   
   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      cout << next << " ";
   }
   return 0;
}

Output:

Leave a Reply

Contact Form

Name

Email *

Message *

Followers