您的位置:首页 > 其它

第8周项目3 多分段函数求值

2014-10-16 14:26 162 查看
/*
* Copyright (c) 2014,烟台大学计算机学院
* All right reserved.
*文件名:eight week2.app
* 作者:柴银平
* 完成时间:2014年10月12日
* 版本号:v1.0
*
* 问题描述:从键盘输入x的值,计算出y的值。
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x,y;
cout<<"请输入x"<<endl;
cin>>x;
if (x<2)
y=x;
else
{
if (x<6&&x>=2)
y=x*x+1;
else
{
if (x<10&&x>=10)
y=sqrt(x=1);
else
y=1/(x+1);
}
}
cout<<"y"<<"="<<y<<endl;
return 0;
}



#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x,y;
char t;
cout<<"请输入x"<<endl;
cin>>x;
t=(x<10)+(x<6)+(x<2);
switch (t)
{ case 3:y=x;break;
case 2: y=x*x+1; break;
case 1: sqrt(x+1);break;
case 0: y1/(x+1);break;
}
cout<<"Y"<<"="<<y<<endl;
return 0;
}

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