fork(1) download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. float FuncFloat(float n);
  7. double FuncDouble(double n);
  8.  
  9. int main(){
  10.  
  11. /*Testing Binet's Function for F(n)=result.
  12. We are going to set N to 10 for these examples.
  13. The 1st is sending and returning a float = 7 digits*
  14. The 2nd one is supposed to return a double = 15 digits*/
  15.  
  16. cout<<"Online Fibonacci Calculators say = F(10) = 55 (2 digits)"<<endl<<endl;
  17.  
  18. float test1 = 10;
  19. cout<<"Using FLOAT - F(10) = "<<FuncFloat(test1);
  20.  
  21. cout<<endl<<endl;
  22.  
  23. double test2=10;
  24. cout<<"Using DOUBLE - F(10) = "<<FuncDouble(test2);
  25.  
  26. //----------------------------------------------------------------------------------------------
  27.  
  28. cout<<endl<<endl;
  29.  
  30. /*Testing Binet's Function for F(n)=result.
  31. We are going to set N to 30 for these examples.
  32. The 1st is sending and returning a float = 7 digits*
  33. The 2nd one is supposed to return a double = 15 digits*/
  34.  
  35. cout<<"Online Fibonacci Calculators say = F(30) = 832040 (6 digits)"<<endl<<endl;
  36.  
  37. test1 = 30;
  38. cout<<"Using FLOAT - F(30) = "<<FuncFloat(test1);
  39.  
  40. cout<<endl<<endl;
  41.  
  42. test2=30;
  43. cout<<"Using DOUBLE - F(30) = "<<FuncDouble(test2);
  44.  
  45. //----------------------------------------------------------------------------------------------
  46.  
  47. cout<<endl<<endl;
  48.  
  49. /*Testing Binet's Function for F(n)=result.
  50. We are going to set N to 31 for these examples.
  51. The 1st is sending and returning a float = 7 digits*
  52. The 2nd one is supposed to return a double = 15 digits*/
  53.  
  54. cout<<"Online Fibonacci Calculators say = F(31) = 1346269 (7 digits)"<<endl<<endl;
  55.  
  56. test1 = 31;
  57. cout<<"Using FLOAT - F(31) = "<<FuncFloat(test1);
  58.  
  59. cout<<endl<<endl;
  60.  
  61. test2=31;
  62. cout<<"Using DOUBLE - F(31) = "<<FuncDouble(test2);
  63.  
  64.  
  65. //WHY dose the double sill error.. it is meant to be 15 digits, there should be plenty of room for this F(30) number?
  66.  
  67.  
  68.  
  69. cout<<endl<<endl<<endl<<"Please Close Console Window"<<endl;
  70. cin.ignore('\n', 1024);
  71. return(0);
  72. }
  73.  
  74.  
  75. float FuncFloat(float n){
  76. float result;
  77. result = (pow(1 + sqrt(5.0f), n) - pow( 1 - sqrt(5.0f),n )) / (pow(2,n) * sqrt(5.0f));
  78. return(result);
  79. }
  80.  
  81.  
  82.  
  83. double FuncDouble(double n){
  84. double result;
  85. result = (pow(1 + sqrt(5.0), n) - pow( 1 - sqrt(5.0),n )) / (pow(2,n) * sqrt(5.0));
  86. return(result);
  87. }
Success #stdin #stdout 0.01s 2732KB
stdin
Standard input is empty
stdout
Online Fibonacci Calculators say = F(10) = 55 (2 digits)

Using FLOAT - F(10) = 55

Using DOUBLE - F(10) = 55

Online Fibonacci Calculators say = F(30) = 832040  (6 digits)

Using FLOAT - F(30) = 832040

Using DOUBLE - F(30) = 832040

Online Fibonacci Calculators say = F(31) = 1346269   (7 digits)

Using FLOAT - F(31) = 1.34627e+06

Using DOUBLE - F(31) = 1.34627e+06


Please Close Console Window