Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <locale.h>
  4.  
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "russian");
  8.    
  9.     double x, e, Sl, Sr;//e - эпсилон, Sl - сумма правой части, Sr - сумма правой части.
  10.     int n = 0;
  11.    
  12.     double chff(double x1){//Функция гипербалического коссинуса
  13.         double S;
  14.         S = (exp(x1)+exp(0-x1))/2;
  15.         return S;
  16.     }
  17.     double fac(double x1){//Функция факториала
  18.         double S;
  19.         S = 1;
  20.         for(double i = 1.; i <= x1; i++){
  21.             S *= i;
  22.         }
  23.         return S;
  24.     }
  25.     printf("Введите значение x: ");
  26.     scanf("%lf", &x);
  27.     Sl = chff(x);
  28.     printf("Введите эпсилон: ");
  29.     scanf("%lf", &e);
  30.     Sr = 1;
  31.     while (fabs(Sl-Sr)>e && n < 1000){
  32.         n++;
  33.         Sr += (pow(x, 2*n))/(fac(2*n));
  34.        
  35.        
  36.     }
  37.     if (n==1000){
  38.         printf("За 1000 шагов функция не сошлась");
  39.     }else{
  40.         printf("Левая часть = %lf, Правая часть = %lf, Вычесленно за %d шагов.", Sl, Sr, n);
  41.     }
  42.    
  43.    
  44.    
  45.     scanf("%lf", &e);
  46.     return 0;  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement