Exercise 2-10 of the title set of "C Language Programming (3rd Edition)" of Zhejiang University

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

This question requires calculating the value of the following piecewise function f(x):
Insert picture description here
Input format:
Input gives a real number x in one line.
Output format: output in the format of
"f(x) = result" in one line, in which x and result both retain one decimal place.
Input example 1:
10
Output example 1:
f(10.0) = 0.1
Input example 2:
0
Output example 2:
f(0.0) = 0.0
Author
Yan Hui
Unit
Zhejiang University City College

Code length limit
16 KB
Time limit
400 ms
memory limit
64 MB

#include <stdio.h>

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

Guess you like

Origin blog.csdn.net/DoMoreSpeakLess/article/details/109249330