fork download
  1. #include<stdio.h>
  2. int f( int h ) ;
  3. int main()
  4. {
  5. int a,n;
  6. double s ;
  7. s=0.0;
  8. scanf("%d",&n);
  9. for(a=1;a<=n;a++)
  10. {
  11. s=s+(double)f(a+2)/f(a+1);
  12. }
  13. printf("%.6f",s);
  14. return 0 ;
  15. }
  16. int f ( int h )
  17. {
  18. int i,o,p,u;
  19. i=o=1;
  20.  
  21. if((h==1)||(h==2))
  22. {
  23. return 1 ;
  24. }
  25. else
  26. {
  27. for(u=3;u<=h;u++)
  28. {
  29. p=i+o;
  30. i=o;
  31. o=p;
  32. }
  33. return p;
  34. }
  35. }
Success #stdin #stdout 0.01s 5312KB
stdin
3
stdout
5.166667