//if()实现
创新互联建站专注于企业全网整合营销推广、网站重做改版、龙海网站定制设计、自适应品牌网站建设、成都h5网站建设、商城系统网站开发、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为龙海等各大城市提供网站开发制作服务。
#includeiostream.h
#includemath.h
void main()
{
double x,y;
cout"Enter X:";
cinx;
if(x0)//永远二分
cout"No defination\n";
else
{ if(x10)
y=sin(x);
else
if(x20)
y=cos(x);
else
if(x30)
y=log(x+1);//ln(x+1)
else
if(x40)
y=-0.5*x;
else
cout"No defination\n";
}
if(x=0x40)
cout"y="yendl;
}
//switch()实现
#includeiostream.h
#includemath.h
void main()
{
double x,y;
cout"Enter X:";
cinx;
switch(int(x/10))//注意这里的技巧
{
case 0:y=sin(x);cout"y="yendl;break;
case 1:y=cos(x);cout"y="yendl;break;
case 2:y=log(x+1);cout"y="yendl;break;
case 3:y=-0.5*x;cout"y="yendl;break;
default:
cout"No defination"endl;
}
}
#include
int main()
{
int x,y;
scanf("%d",x);
if(0xx10) y=3*x+2;
else
{if(x=0) y=0;
else
{if (x0) y=x*x;
else printf("go die\n");
}
}
printf("%d",y);
return 0;
}该程序的分段函数如下:
f(x)=3x+2 (0x10)
f(x)=1 (x=0)
f(x) = x*x (x0)
#include stdio.h
#include math.h
void main()
{
float x;
double y;
printf("Please input the value of x:");
scanf("%f",x);
if(x=-10x=4)
{
y=fabs(x-2);
printf("y=%.2f\n",y);
}
else if(x=5x=7)
{
y=x+10;
printf("y=%.2f\n",y);
}
else if(x=8x=12)
{
y=pow(x,4);
printf("y=%.2f\n",y);
}
else
printf("No answer\n");
}
#include stdio.h
#include math.h
int SegmentFunction(int x){
if(x 1) return x;
else
if(x 10 || x == 10) return 3 * x -11;
else return 2 * x -1;
}
int main()
{
int in;
scanf("%d", in);
printf("%d", SegmentFunction(in));
return 0;
}
// 这种代码我都懒的署名
#includeiomanip//小数位输出控制函数头文件;
#includeiostream
using namespace std;
int main()
{
float x,y;
cinx;
if(x=0x5)
y=-x+2.5;
if(x=5x10)
y=2-1.5*(x+3)*(x-3);
if(x=10x20)
y=x/2-1.5;
cout.setf(ios::showpoint);
cout.precision(3);//用来控制小数位输出;
cout.setf(ios::fixed);
couty;
return 0;
}