Advertisement
luluwwl

Untitled

Feb 5th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int findFibonaci(int);
  6.  
  7. int main() {
  8. int n=2;
  9. double target,precision=100.00,ratio,ratioDor=(1+sqrt(5))/2;
  10.  
  11. cout << "Quelle precision vous voulez? ";
  12. cin >> target;
  13. cout << endl;
  14.  
  15. while (precision > target) {
  16. ratio = findFibonaci(n) / findFibonaci(n - 1);
  17. precision = abs(ratio - ratioDor);
  18. n++;
  19. }
  20.  
  21. cout << "Vous pouvez utiliser " << n << "ieme de Fibonaci nombre." << endl;
  22.  
  23. system("pause");
  24. return 0;
  25. }
  26.  
  27. int findFibonaci(int n) {
  28. int num;
  29. if (n >2) {
  30. num = findFibonaci(n - 1) + findFibonaci(n - 2);
  31. }
  32. else {
  33. num = 1;
  34. }
  35.  
  36. return num;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement