第八周项目二:多分段函数求值(1)

来源:互联网 发布:有毒网络剧有第二季吗 编辑:程序博客网 时间:2024/05/16 03:34
/* *copyright (c) 2014, 烟台大学计算机学院 *All rights reserved.*文件名称:test.cpp *作者:陆云杰*完成日期:2014年10月16日 *版本号:v1.0* * *问题描述:用 if else求多分段函数的值*输入描述:一个整数x*程序输出:对应y的值*/#include <iostream>#include <cmath>using namespace std;int main(){    int 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<<"y="<<y<<endl;    return 0;}


知识点总结:用多个if else 结构来解决多分段函数的求值。

学习心得:学到了多个if else 解决问题的方法。

0 0