第八周项目3.1分段函数求值

来源:互联网 发布:sql删除数据库表数据 编辑:程序博客网 时间:2024/05/16 11:17

问题及代码:

/*
*Copyringht (c) 2014,烟台大学计算机学院
*All right reserved.
*文件名称: test.cpp
*作    者:马明城
*完成日期:2014年10月19日
*版本号:  v1.0


*问题描述:输入X.Y求值

*输入描述:输入1个整数,代表x
*程序输出:输出一个整数,代表y
*/

#include <iostream>
#include <math.h>                          // 要调用 sqrt用到这个语句
using namespace std;
int main()
{ double x,y,t;                             
    cout << "输入x的值:";
    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 if(x>=10) y=1/(x+1);
  
    
    cout<<"输出y的值:"<<y<<endl;
    return 0;
}

运行结果:



0 0
原创粉丝点击