Advertisement
Guest User

lab4

a guest
Oct 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. double input(void);
  4.  
  5. int main(){
  6.     double pgrnst=input(), zs1, zs2=1, rznst;
  7.     int fib1=1, fib2=1, buf;
  8.     int i=1;
  9.     do{
  10.         zs1 = zs2;
  11.         buf = fib2;
  12.         fib2 += fib1;
  13.         fib1 = buf;
  14.         zs2 = (double)fib2/fib1;
  15.         rznst = (zs2-zs1)<0 ? zs1-zs2: zs2-zs1;
  16.         i++;
  17.     }
  18.     while(rznst>pgrnst);
  19.     printf("%.10lf\n", zs2);
  20.     printf("Nomer shaga: %d\n", i);
  21. }
  22. double input(){
  23.     double a;
  24.     while(scanf("%lf", &a)!=1 && a>0){
  25.         while(getchar()!='\n');
  26.         printf("Enter correct value: ");
  27.     }
  28.     return a;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement