c分段函数怎么写

1.c语言分段函数怎么写#include "stdio.h"
#include "math.h"
int main(int argc,char *argv[]){
double x,y;
printf("Input x(R:) 。\nx=");
scanf("%lf",&x);
if(x<5)
y=-x+3.5;
else if(x>=5 && x<10)
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;
}运行样例:
2.C语言编程分段函数怎么写#include
#include
int main()
{
using namespace std;
cout10):";
double x,y;
cin>>x;
int n;
if(x>=10&&xn=1;
else if(x>=20&&xn=2;
else if(x>=30&&xn=3;
else if(x>=40&&xn=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:
coutbreak;
}
if(x>10)
coutreturn 0;
}
3.怎么用c语言编程一个分段函数1. #include
int main()
{
int x,y;
scanf("%d",&x);
if(0<x&&x<10) y=3*x+2;
else
{if(x=0) y=0;
else
{if (x<0) y=x*x;
else printf("go die\n");
}
}
printf("%d",y);
return 0;
}该程序的分段函数如下:
f(x)=3x+2 (0<x<10)
f(x)=1 (x=0)
f(x) = x*x (x<0)
2. #include <stdio.h>
#include <math.h>
void main()
{
float x;
double y;
printf("Please input the value of x:");
scanf("%f",&x);
if(x>=-10&&x<=4)
{
y=fabs(x-2);
printf("y=%.2f\n",y);
}
else if(x>=5&&x<=7)
{
y=x+10;
printf("y=%.2f\n",y);
}
else if(x>=8&&x<=12)
{
y=pow(x,4);
printf("y=%.2f\n",y);
}
else
printf("No answer\n");
}
4.C语言写计算分段函数#include <stdio.h>
【c分段函数怎么写】#include <math.h>
int main(void)
{
int repeat, ri;
double x, y;
scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%lf",&x);
y=x>=0?sqrt(x):pow(x+1,2)+2*x+1/x;
printf("f(%.2f) = %.2f\n", x, y);
}
}
5.计算分段函数显然来 , 依据题自意 , 
那么知就有道:
#include <stdio.h>
#include <math.h>
int main(){
double x;
scanf("%lf",&x);
if(x<4) printf("%.2lf",2*x);
else if(x>9) printf("%.2lf",x*sqrt(3));
else printf("%.2lf",x*x*x);
return 0;
}
6.用C语言写一个分段函数int i = 76;
int ii = i/10;
switch (ii)
{
case 1 :
case 2:
case 3:
case 4:
case 5:
printf("<60");
break;
case 6:
case 7:
printf("<80");
break;
case 8:
case 9:
case 10:
printf(">=80");
break;
default:
break;
}

c分段函数怎么写

文章插图