7-10 Calculate the piecewise function [2] (10 points)

This topic requires calculating the value of the following piecewise function f(x):

Insert picture description here

Note: You can include math.h in the header file, and call the sqrt function to find the square root, and call the pow function to find the exponentiation.

Input format:
Input a real number x in one line.

Output format: output in the format of
"f(x) = result" in one line, where x and result both retain two decimal places.

Input example 1:

10

Output sample 1:

f(10.00) = 3.16
#include<stdio.h>
#include<math.h>
int main (void)
{
    
    
		double x, result;
		scanf("%lf", &x);
	if(0<=x){
    
    
		result=sqrt(x);
	    printf("f(%.2lf) = %.2lf", x, result);
	}
	else{
    
    
		result=pow((x+1), 2)+2*x+1.0/x;
		printf("f(%.2lf) = %.2lf", x, result);
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45814538/article/details/108886009