Advertisement
am1x

tmp006.cpp

Oct 4th, 2023 (edited)
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | Fixit | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <assert.h>
  4.  
  5.  
  6. double f(double x)
  7. {
  8.     if (!(-7 <= x && x <= 7))
  9.         return nan("");
  10.     if (x < 2) {
  11.         if (x <= -2)
  12.             return -0.8 * (7 + x);
  13.         else
  14.             return -4 - sqrt((2 - x) * (2 + x));
  15.     } else {
  16.         if (x <= 5)
  17.             return -4.0;
  18.         else
  19.             return 3 * (x - 6) - 1;
  20.     }
  21. }
  22.  
  23. int main()
  24. {
  25.     double x = 0;
  26.     int st = scanf("%lf", &x);
  27.     assert (st == 1);
  28.     double y = f(x);
  29.     printf("f(%.16f) = %.16f\n", x, y);
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement