Experiment 2-2-6 Calculating the piecewise function [3] (10 points)

This question requires calculating f(x)the value of the following piecewise function :
y = f (x) = {xx != 10 1 / xx = 10 y = f(x) = \begin{cases} x& \text{x != 10}\ \1/x& \text{x = 10} \end{cases}Y=f(x)={ x1/xx != 10x = 10

Input format:

The input gives the real number x in one line.

Output format:

“f(x) = result”Output in the format in one line , in which x and result both retain one decimal place.

Input example 1:

10

Output sample 1:

f(10.0) = 0.1

Input example 2:

234

Output sample 2:

f(234.0) = 234.0

Code:

# include <stdio.h>
# include <stdlib.h>

int main(){
    
    
    double x,result;
    scanf("%lf",&x);
    if (x == 10) result = 1.0 / x;
    else result = x;
    printf("f(%.1lf) = %.1lf",x,result);
    return 0;
}

Submit screenshot:

Insert picture description here

Problem-solving ideas:

Basic operation, the previous questions have already been explained ~ familiarity is fine

Guess you like

Origin blog.csdn.net/weixin_43862765/article/details/114385558