2 Star 6 Fork 3

Cyouagain / C语言经典编程详解

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
【C语言经典编程】练习2-11 计算分段函数[2] (10分).md 1.29 KB
一键复制 编辑 原始数据 按行查看 历史

微信搜索公众号【IT学长】:

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

本题目要求计算下列分段函数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

代码:

#include<stdio.h>
#include<math.h>
int main()
{
  double x;
  scanf("%lf\n",&x);
  if(x>=0) printf("f(%.2lf) = %.2lf\n",x,pow(x,0.5));
  else printf("f(%.2lf) = %.2lf\n",x,pow(x+1,2)+2.0*x+1/x);
  return 0;
}
C
1
https://gitee.com/cyouagain/C_pta.git
git@gitee.com:cyouagain/C_pta.git
cyouagain
C_pta
C语言经典编程详解
master

搜索帮助