问题及代码:
/*。
*Copyright(c)2014,烟台大学计算机学院
*All right reserved,
*文件名:test.cpp
*作者:liu_feng_zi_
*完成日期:2014年10月15日
*版本号:v1.0
*
问题描述:
*输入描述:输入x
*程序输出:输出Y
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float 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/x+1;
cout<<y<<endl;
return 0;
}
运行结果:
知识点总结:开根号是用“sqrt”;程序中要使用根号时,要使用“include cmath”,多分支时使用“else if”
学习心得:在c++中,每个字符都有自己特定的存在区域。