/*
*Copyright (c) 2014,烟台大学计算机学院
*All rights reserved.
*文件名称: test.cpp
*作 者:李晓凡
*完成日期:2014年10月16日
*版本号:v1.0
*
*问题描述:用switch求多分段函数值
*输入描述:自变量X
*程序输出:因变量Y
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x,y,z;
cin >>x;
z=(x<2)+(x<6)+(x<10);
switch(z)
{
case 0:y=1/(x+1);break ;
case 1:y=1/(x+1);break ;
case 2:y=sqrt(x+1);break;
case 3:y=x;break;
}
cout << "对应的y值为" << y<<endl;
return 0;
}
*Copyright (c) 2014,烟台大学计算机学院
*All rights reserved.
*文件名称: test.cpp
*作 者:李晓凡
*完成日期:2014年10月16日
*版本号:v1.0
*
*问题描述:用switch求多分段函数值
*输入描述:自变量X
*程序输出:因变量Y
*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x,y,z;
cin >>x;
z=(x<2)+(x<6)+(x<10);
switch(z)
{
case 0:y=1/(x+1);break ;
case 1:y=1/(x+1);break ;
case 2:y=sqrt(x+1);break;
case 3:y=x;break;
}
cout << "对应的y值为" << y<<endl;
return 0;
}