第八周2-计算函数值

来源:互联网 发布:淘宝优惠微信群二维码 编辑:程序博客网 时间:2024/05/21 07:06
/**copyright (c) 2013,烟台大学计算机学院*All rights reserved.*作者:石尧*完成日期:2013年10月16日*版本号:v1.0*问题描述:计算函数的值。*样例输入:1  2*样例输出:2  5*问题分析:输入x,按公式求出y的值并输出。*/#include <iostream>#include <cmath>using namespace std;int main(){int x,y;cout<<"请输入一个数"<<endl;cin>>x;if(x<2)cout<<"y="<<x<<endl;else if(x<6){y=x*x+1;cout<<"y="<<y<<endl;}else if(x<10){y=sqrt(x+1);cout<<"y="<<y<<endl;}else// if(x>=10){y=1/(x+1);cout<<"y="<<y<<endl;}return 0;}