zoukankan      html  css  js  c++  java
  • 练习2-11 计算分段函数[2] (10 分)

    练习2-11 计算分段函数[2] (10 分)

    本题目要求计算下列分段函数f(x)的值:

    注:可在头文件中包含math.h,并调用sqrt函数求平方根,调用pow函数求幂。

    输入格式:

    输入在一行中给出实数x。

    输出格式:

    在一行中按“f(x) = result”的格式输出,其中x与result都保留两位小数。

    输入样例1:

    10
    

    输出样例1:

    f(10.00) = 3.16
    

    输入样例2:

    -0.5
    

    输出样例2:

    f(-0.50) = -2.75


     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <math.h>
     4 
     5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     6 
     7 int main(int argc, char *argv[]) {
     8 double x,y;
     9 scanf("%lf",&x);
    10 
    11 if (x>=0)
    12 y=sqrt(x);    
    13 
    14 else 
    15 y=pow(x+1,2)+2.0*x+1.0/x;
    16 printf("f(%.2f) =%.2f",x,y);
    17 
    18 return 0;
    19 }
    20 
    21  
  • 相关阅读:
    大数据学习操作笔记
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    每日总结
    jstl标签,c:foreach无效的问题
    阅读笔记
    《高效能人士的7个习惯》
  • 原文地址:https://www.cnblogs.com/xxl-h/p/11110869.html
Copyright © 2011-2022 走看看