分段函数求值 c语言14
发布网友
发布时间:2023-11-24 05:28
我来回答
共3个回答
热心网友
时间:2024-12-01 05:08
# include <stdio.h>
# include <math.h>
void main()
{
int x;
int y;
while(1)
{
printf("input x:\n");
scanf("%d",&x);
if(x<-2)
{
y=7-2*x;
}
else if(x>=-1 && x<3)
{
y=5-abs(3*x+2);
}
else
{
y=3*x+4;
}
printf("y is %d\n\n",y);
}
}
这样就可以了,望采纳!
热心网友
时间:2024-12-01 05:08
#include "stdio.h"
#include "math.h"
int main(){
int x,y;
scanf("%d",&x);
if(x<-2)
y=7-2x;
else if(x>-2 &&x<3)
y=5-abs(3x 2);
else
y=3x 4;
printf("%d",y);
}
热心网友
时间:2024-12-01 05:09
#include<stdio.h>
#include<stdlib.h>
main{}{
int x,ans;
while(scanf("%d",&x)!=EOF){
if(x<-2)ans=7-2*x;
else if(x>=-2&&x<3)ans=5-abs(3*x+2);
else ans=3*x+4;
printf("%d\n",ans);
}
}