第八周项目3

来源:互联网 发布:淘宝买的补漆套装 编辑:程序博客网 时间:2024/05/16 10:41

*   Copyright  (c)   2014, 烟台大学计算机学院

*   All  rights  reserved.

*   文件名称 :test.cpp

*   作        者 :吴英政

*   完成日期 :2014年10月11号

*   版 本 号 :v1.0

*

*   问题描述 :计算函数的值:当x<2时, y=x;  2<=x<6时,y=x*x+1;  6<=x<10时, y=sqrt(x+1);   x>=10时,   1/x+1

*   输入描述 :一个整数x

*   程序输出 :对应的y值

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    double x,y;
    int z;
    cin>>x;
    z=(x<2)+(x<6)+(x<10);
    switch(z)
{
    case 3: y=x;break;
    case 2: y=x*x*+1;break;
    case 1: y=sqrt(x+1);break;
    case 0: y=1/(x+1);break;
}
    cout << "y=" <<y<< endl;
    return 0;
}

0 0
原创粉丝点击