ostapdontstop

ebobo

Jan 16th, 2018
172
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. main(){
  5.     float x, a, sum, eps=1e-4;
  6.     int i=1, lim=1000;
  7.     printf("Input x: ");
  8.     scanf("%f", &x );
  9.     a = sum = 1;
  10.     for (i; fabs(a) >= eps ; i++){
  11.        
  12.         a*= x*x/(2*i)/(2*i-1);
  13.         sum+=a;
  14.  
  15.         if (i > lim) {
  16.             printf("divergents");
  17.             break;
  18.         }
  19.     }
  20. if (i <= lim)
  21.     printf("ch(%.1f): %f\ntest:\t %f" , x, sum, cosh(x));
  22. }
RAW Paste Data