一、问题及代码
/*
* 文件名称:
* 作 者: 张琪
* 完成日期: 2016年4月7日
* 版 本 号:v1.0
* 对任务及求解方法的描述部分:
* 输入描述: 无
* 问题描述: if-else语句的使用
* 程序输出:
* 问题分析:
* 算法设计:
*/
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double x,y,d;
cout<<"请输入x:";
cin>>x;
d=x+1;
if(x<2)
y=x;
else if(2<=x&&x<6)
y=x*x+1;
else if(6<=x&&x<10)
y=sqrt(d);
else if(x>=10)
y=1/(x+1);
cout<<y<<endl;
return 0;
}
二 运行结果
三、心得体会:第三次上机做报告,对if sles语句又有了了解了。
四、知识点总结:自己对这个语句的编程还是不了解,需要多看看课本,熟练一下。我知道了有sqrt(),前面要加上#include<cmath>。