实验2-2-1 计算分段函数[1] (10 分)
1. 题目摘自
https://pintia.cn/problem-sets/13/problems/395
2. 题目内容
本题目要求计算下列分段函数f(x)的值:
7.jpg
输入格式:
输入在一行中给出实数x。
输出格式:
在一行中按“f(x) = result”的格式输出,其中x与result都保留一位小数。
输入样例1:
10
输出样例1:
f(10.0) = 0.1
输入样例2:
0
输出样例2:
f(0.0) = 0.0
3. 源码参考
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float x;
cin>>x;
//f(10.0) = 0.1
if(x==0)
{
cout<<"f(0.0) = 0.0"<<endl;
}
else
{
cout<<"f("<<fixed<<setprecision(1)<<x<<") = "<<1/x<<endl;
}
return 0;
}