Exercise 2-11 Measurements of Function [2] (10 minutes)
The title calculate the following claims piecewise function F ( X value):
Note: included in the header file math.h
and call the sqrt
function square root, call the pow
function exponentiation.
Input formats:
Input gives the real number x in a row.
Output formats:
In a row by "f (x) = result" output format, wherein x and result are two decimal places.
Sample Input 1:
10
Output Sample 1:
f(10.00) = 3.16
Sample Input 2:
-0.5
Output Sample 2:
f(-0.50) = -2.75
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
double x,y;
scanf("%lf",&x);
if (x>=0)
y=sqrt(x);
else
y=pow(x+1,2)+2.0*x+1.0/x;
printf("f(%.2f) =%.2f",x,y);
return 0;
}