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

来源:互联网 发布:浪迹网络课程 编辑:程序博客网 时间:2024/05/29 12:30
/** Copyright (c) 2014,烟台大学计算机学院* All right reserved.*文件名称:new.cpp* 作者:郭栋* 完成时间:2014年10月16日* 版本号: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)        y=x*x+1;    else if(x<10)        y=sqrt(x+1);    else        y=1/(x+1);   cout<<"y="<<y<<endl;    return 0;}


运行结果:

知识点总结:第一次做多分支结构,没想到第一次唯一的错误竟然是没有输出结果。。。。额,就这样吧

学习心得:再次加油,only next

0 0
原创粉丝点击