第8周项目 3——2 多多分段函数求值

来源:互联网 发布:手机拍照定位软件 编辑:程序博客网 时间:2024/06/08 17:33
/*

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

   *   all  rights   reserved  .

   *   文件名称   :    textst  .    cpp

   *    作者  :    孙旭明

   *     完成日期    :    2014年10月18日

   *     版本号    :     v1.0

   *

* 问题描述 :    多分段函数求值

   *    输入描述    : 一 个整数 x

   *      程序输出    :     对应的函数值y

   */

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
  int  t, x,y;
  cin >>x;
      t =(x<2)+(x<6)+(x<10);
      switch (t)
      {
          case   0:y=1/(1+x);break;
          case   1:y=sqrt (x+1);break;
          case   2:y=x*x+1;break;
          case   3:y=x;break;
      } cout << "函数的值为" <<y<< endl;
    return 0;
}

0 0