This C++ Program generates Fibonacci Series upto 1000. Here the first two numbers in the Fibonacci Series are 0 and 1 and the rest of the numbers are obtained by adding previous two numbers.
Here is source code of the C++ program which generates Fibonacci Series upto 1000. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ program to generate fibonacci series upto 1000
*/
#include<iostream>
using namespace std;
int main()
{
int fib1 = 0, fib2 = 1, fib3 = 1;
cout << "The Fibonacci Series is follows : " << endl << fib1 << " " << fib2 << " ";
while (fib1 + fib2 < 1000)
{
fib3 = fib1 + fib2;
fib1 = fib2;
fib2 = fib3;
cout << fib3 << " ";
}
cout << endl;
return 0;
}
$ g++ main.cpp $ ./a.out The Fibonacci Series is follows : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Apply for C++ Internship
- Check Computer Science Books
- Check Programming Books
- Practice Computer Science MCQs
- Practice Programming MCQs