ostapdontstop

Untitled

Jan 16th, 2018
156
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.     do {
  8.     printf("Input x [-1; 1]: ");
  9.     scanf("%f", &x );
  10.     }   while(x > 1 || x < -1);
  11.     a = sum = 1;
  12.     for (i; fabs(a) >= eps ; i++){
  13.        
  14.         a*= x*x/(2*i)/(2*i-1);
  15.         sum+=a;
  16.  
  17.         if (i > lim) {
  18.             printf("divergents");
  19.             break;
  20.         }
  21.     }
  22. if (i <= lim)
  23.     printf("ch(%.1f): %f\ntest:\t %f" , x, sum, cosh(x));
  24. }
RAW Paste Data