您的位置:首页 > 其它

项目三 多分段函数求值 (1)用if~else~语句的嵌套

2014-10-16 14:42 253 查看
/*

*Copyright (c) 2014,烟台大学计算机学院

*All rights reserved.

*文件名称:first.cpp

*作者:刘天恩

*完成时间:2014年10月16号

*版本号:v1.0

*问描述:输入x,计算并输出y的值

*输入描述:输入x

*程序输出:输出y

*/

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x,y;
cin>>x;
if(x<2)
y=x;
else if(x>=2&&x<6)
y=x*x+1;
else if(x>=6&&x<10)
y=sqrt(x+1);
else
y=1.0/(x+1);
cout<<"y="<<y<<endl;
return 0;
}


运行结果:







内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: