Friday, 10 February 2017

How print fibonacci sequence in C++?

#include<iostream>
#include<string>

using namespace
std;
int main()
{
 int range;
 cout << "Enter the range of the numbers: " << endl;
 cin >> range;
 int first=1;
 int second=1;
 int third=0;
 cout << "\n your result is here : " << endl;
 cout << first << " , " << second << " , ";
 for (int i = 2; i < range; ++i) {
  third = first + second;
  first = second;
  second = third;
  cout << third << " , ";
 }

 cout << endl;
 system("pause");
 return 0;
}

No comments:

Post a Comment