编写程序,有如下分段函数?

编写程序,有如下分段函数?,第1张

按照题目要求编写的分段函数的C语言程序如下

#include<stdio.h>

int main(){

float x,y

scanf("%f",&x)

if(x==1){

y=2*x-1

}else{

y=1/(1-x*x)

}

printf("%f\n",y)

return 0

}

#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)

#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")

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8095390.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存