am1x icon

tmp006.cpp

am1x | PRO | 10/05/23 12:35:12 AM UTC (Edited) | 0 ⭐ | 3599 👁️ | Never ⏰ | []
C++ |

470 B

|

Fixit

|

0 👍

/

0 👎

#include <stdio.h>
#include <math.h>
#include <assert.h>
 
 
double f(double x)
{
    if (!(-7 <= x && x <= 7))
        return nan("");
    if (x < 2) {
        if (x <= -2)
            return -0.8 * (7 + x);
        else
            return -4 - sqrt((2 - x) * (2 + x));
    } else {
        if (x <= 5)
            return -4.0;
        else
            return 3 * (x - 6) - 1;
    }
}
 
int main()
{
    double x = 0;
    int st = scanf("%lf", &x);
    assert (st == 1);
    double y = f(x);
    printf("f(%.16f) = %.16f\n", x, y);
    return 0;
}
 

Comments