练习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 }