Example Program For Fibonacci Series Using Loop In C++


SUBMITTED BY: Nrupeshsinh

DATE: June 24, 2016, 8:29 a.m.

FORMAT: Text only

SIZE: 464 Bytes

HITS: 745

  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. int main()
  5. {
  6. // Variable Declaration
  7. int counter, n;
  8. long last=1,next=0,sum;
  9. // Get Input Value
  10. cout<<"Enter the Number :";
  11. cin>>n;
  12. //Fibonacci Series Calculation
  13. while(next<n/2)
  14. {
  15. cout<<last <<" ";
  16. sum=next+last;
  17. next=last;
  18. last=sum;
  19. }
  20. // Wait For Output Screen
  21. getch();
  22. return 0;
  23. }

comments powered by Disqus