Tuesday, 15 November 2016

Write a program that inputs a number form the user and display Fibonacci series upto number entered.


Write a program that inputs a number form the user and display Fibonacci series upto number entered.

Solution : 


#include <iostream.h>
#include <conio.h> 
int main ()
{
int a, b, next, n;
clrscr();
cout<< "Enter the number upto which fibonacci series is required: " ;
cin>>n;
cout<< "Fibonacci series upto "<< n<< "is " << endl;
a = 0 ;
b = 1 ;
cout<< a<< " "<< b;
next = a + b;
while (next <= n)
  {
   cout << " "<< next;
   a = b;
   b = next;
   next = a + b;
}
return 0;
}




Output:

No comments:

Post a Comment

If you have any doubt please let me know

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...