Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double inp()
  5. {
  6.     double ac;
  7.     printf("Input accuracy\n");
  8.     while(scanf("%lf", &ac) != 1)
  9.     {
  10.         while(getchar() != '\n');          
  11.         printf("ERROR\n");
  12.     }
  13.         return ac;
  14. }
  15. int fib(int n)
  16. {
  17.     int i;
  18.     int f1=0;
  19.     int f2=1;
  20.     int f3=1;
  21.    
  22.     for (i=3; i<=n+1; i++)
  23.     {
  24.         f3= f1+f2;
  25.         f1= f2;
  26.         f2= f3;
  27.     }
  28.     return (f3);
  29. }
  30. double result(double ac)
  31. {
  32.     int i=1;
  33.     double r;
  34.     int fib1, fib2, fib3;
  35.     do
  36.     {
  37.         fib1=fib(i);
  38.         fib2=fib(i+1);
  39.         fib3=fib(i+2);
  40.         r=fabs(((double)fib3/(double)fib2)-((double)fib2/(double)fib1));
  41.         i++;
  42.     }
  43.     while(r>ac);
  44.     return ((double)fib3/(double)fib2);
  45. }
  46.  
  47. main(void)
  48. {
  49.     double ac;
  50.     ac=inp();
  51.     printf("%.7lf\n", result(ac));
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement