Guest User

Untitled

a guest
Jul 16th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int fib(int n);
  6.  
  7. int main() {
  8.  
  9. for(int i=0; i < 10; i++) {
  10. cout << fib(i) << endl;
  11.  
  12. }
  13. return 0;
  14. }
  15.  
  16. int fib(int n) {
  17. int newnum;
  18. if (n == 0 || n == 1){
  19. newnum = n;
  20. }
  21. else if (n > 1) {
  22. newnum = fib(n-2) + fib(n-1);
  23. }
  24. return newnum;
  25. }
Add Comment
Please, Sign In to add comment