Advertisement
gosuodin

fibonacci

Jun 6th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int fibonacci(int n) {
  5. if ((n == 1) || (n == 2)) {
  6. return 1;
  7. }
  8. else {
  9. return fibonacci(n - 1) + fibonacci(n - 2);
  10. }
  11. }
  12. void main() {
  13. int n;
  14. cout << "nhap n :";
  15. cin >> n;
  16. cout << fibonacci(n);
  17. system("pause");
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement