重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#include iostream
创新互联建站专注于灵宝企业网站建设,响应式网站设计,商城建设。灵宝网站建设公司,为灵宝等地区提供建站服务。全流程按需网站策划,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务
#include cmath
int main()
{
using namespace std;
cout"请输入x的值(x10):";
double x,y;
cinx;
int n;
if(x=10x20)
n=1;
else if(x=20x30)
n=2;
else if(x=30x40)
n=3;
else if(x=40x50)
n=4;
else if(x=50)
n=5;
switch(n)
{
case 1:
y=log10(x);
break;
case 2:
y=log10(x)/log10(3);
break;
case 3:
y=cos(x);
break;
case 4:
y=pow(x,5);
break;
case 5:
y=1.0/tan(x);
break;
default:
cout"\n你输入的值不在取值范围内,再见!\n";
break;
}
if(x10)
cout"\n本函数的y值为:"y"。*^o^*\n";
return 0;
}
#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 main()
{
float x, result;
printf("请输入x的值:");
scanf("%f",x);
if(x = 0)
{
result = 0;
}
else if(x = 10)
{
result = sqrt(x);
}
else
{
result = 2 * x + 3;
}
printf("%f",result);
return 0;
}
扩展资料:
c语言计算分段函数值的简单代码:
#include stdio.h
#include math.h
int main()
{
double x,y;
printf("input x:\n");
scanf("%lf",x);
if (x -1.0) y=x*x*x-1;
else if (x =-1 x = 1) y=-3*x+1;
else if (x1 x =10) y=3*exp(2*x-1)+5;
else y = 5*x + 3.0* log10(2*x*x-1) -13;
printf("%.2lf\n",y);
return 0;
}
#include "stdio.h"
#include "math.h"
int main(int argc,char *argv[]){
double x,y;
printf("Input x(R:)...\nx=");
scanf("%lf",x);
if(x5)
y=-x+3.5;
else if(x=5 x10)
y=20-3.5*pow(x+3,7);//这里看着像7,是几就把7改成几
else
y=-3.5+sin(x);
printf("y = %g\t(x==%g)\n",y,x);
return 0;
}
运行样例: