練習2-10 計算分段函數[1] (10 分)


練習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 }

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM