一、问题及代码
二、运行结果
三、心得体会
四、知识点总结
上机内容:C++程序的编写和运行
上机目的:掌握简单C++程序的编译、运行过程
#include<iostream>
#include <cmath>
using namespace std;
int main()
{
float x,y;
cout<<"请输入x:";
cin>>x;
if(x<2)
y=x;
else if(x<6)
y=x*x+1;
else if(x<10)
y=sqrt(x+1);
else
y=1/(x+1);
cout<<"x="<<x<<",y="<<y<<endl;
return 0;
}
运行结果
心得体会
分段函数求值需要考虑多种结果
知识点总结
else-if可用于分段函数求值
转载请注明原文地址: https://ju.6miu.com/read-4059.html