摘要:
练习2-10计算分段函数[1](10分)本主题要求计算以下分段函数f(x)的值:输入格式:在一行中输入实数x。输出格式:以“f(x)=结果”的格式在一行中输出,其中x和result都保留小数位数。输入样本1:10输出样本1:f(10.0)=0.1输入样本2:0输出样本2:f(0.0)=0.01#包含<;标准。h>;2#包括<;标准库.h
练习2-10 计算分段函数[1] (10 分)
本题目要求计算下列分段函数f(x)的值:
输入格式:
输入在一行中给出实数x。
输出格式:
在一行中按“f(x) = result”的格式输出,其中x与result都保留一位小数。
输入样例1:
10
输出样例1:
f(10.0) = 0.1
输入样例2:
0
输出样例2:
f(0.0) = 0.0
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 5 6 int main(int argc, char *argv[]) { 7 double 8 x,f; 9 scanf("%lf",&x); 10 if (x==0){ 11 f=0;} 12 13 else14 f=1/x; 15 16 printf("f(%.1f) = %.1f",x,f); 17 18 return 0; 19 }