fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. double f(int n)
  6. {
  7. double x = (1 + pow(5, 0.5)) / 2;
  8. return (pow(x, n) - pow((x - pow(5, 0.5)), n)) / pow(5, 0.5);
  9. }
  10.  
  11. int main()
  12. {
  13. cout << "Enter the number... ";
  14. int a;
  15. cin >> a;
  16.  
  17. double z;
  18. z = f(a);
  19.  
  20. cout << "n th Fibonacci num is= " << z;
  21. return 0;
  22. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Enter the number... n th Fibonacci num is= inf