fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int f(int n)
  6.  
  7.  
  8. {
  9.  
  10. int f[n+1];
  11. f[0]=0,
  12. f[1]=1;
  13. if(n<2){return f[n]; }
  14.  
  15.  
  16. else{
  17.  
  18. for(int i=2;i<=n;i++){
  19.  
  20.  
  21. f[i]=f[i-1]+f[i-2];
  22.  
  23.  
  24.  
  25. }
  26.  
  27. }
  28.  
  29. return f[n];
  30.  
  31.  
  32.  
  33. }
  34.  
  35. int fn(int n){
  36.  
  37. int a=0,b=1,c=0;
  38.  
  39. if(n<2)return n;
  40.  
  41. else
  42.  
  43. for(int i=2;i<=n;i++){
  44.  
  45. c=a+b;
  46. a=b;
  47. b=c;
  48.  
  49.  
  50. }
  51.  
  52. return b;
  53.  
  54.  
  55. }
  56.  
  57.  
  58. int main() {
  59. // your code goes here
  60.  
  61. cout<<f(11);
  62.  
  63.  
  64.  
  65.  
  66. }
Success #stdin #stdout 0.01s 5516KB
stdin
Standard input is empty
stdout
89