fork download
  1. // Online C++ compiler to run C++ program online
  2. #include <iostream>
  3. using namespace std;
  4. int fib(int n){
  5. int arr[n]={0,1};
  6. // arr[n]={0,1};
  7. for(int i= 0 ;i<=n;i++){
  8. // 0 1 1 2 3 5 8 13
  9. arr[i+2]=arr[i]+arr[i+1];
  10. cout << arr[i] << " ";
  11. }
  12. cout<< endl;
  13. cout << arr[n];
  14. return 0;
  15. }
  16. int main() {
  17. fib(6);
  18. return 0;
  19. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
0  1  1  2  3  5  8  
8