實(shí)驗(yàn)2-2-6 計(jì)算分段函數(shù)[3] (10 分)
1. 題目摘自
https://pintia.cn/problem-sets/13/problems/400
2. 題目內(nèi)容
本題目要求計(jì)算下列分段函數(shù)f(x)的值:
24.jpg
輸入格式:
輸入在一行中給出實(shí)數(shù)x。
輸出格式:
在一行中按“f(x) = result”的格式輸出,其中x與result都保留一位小數(shù)宗雇。
輸入樣例1:
10
輸出樣例1:
f(10.0) = 0.1
輸入樣例2:
234
輸出樣例2:
f(234.0) = 234.0
3. 源碼參考
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double x,y;
cin>>x;
if(x!=10)
{
y=x;
}
else
{
y=1/x;
}
cout<<"f("<<fixed<<setprecision(1)<<x<<") = "<<y<<endl;
return 0;
}