#include <stdio.h>
#include <string.h>
int main()
{
float x,y;
printf("x=");
scanf("%f",&x);
if(x<1)//if成立执行下面的语句;下同理;
y=x;
if(x>=1&&x<10)
y=2*x-1;
if(x>=10)
y=3*x-11;
printf("y=%.2f",y);//%后是(.)几就保留几位小数;
return 0;
}
希望能帮到你,望采纳;
代码如下
望采纳,感谢
#include <stdio.h>
double fun(){
double x;double y;
scanf("%lf",&x);
if(x<1.0){
y=x;
}else if(x>=1.0&&x<10.0){
y=2.0*x-1.0;
}else{
y=3.0*x-11.0;
}
return y;
}
double fun2(double x){
double y;
if(x<1.0){
y=x;
}else if(x>=1.0&&x<10.0){
y=2.0*x-1.0;
}else{
y=3.0*x-11.0;
}
return y;
}
void main(){
//下面注释的部分是使用fun2函数进行测试,恢复即可调试
/*double x1=0.5;double x2=3.0;double x3=7.0;
printf("%.2lf\n",fun2(x1));
printf("%.2lf\n",fun2(x2));
printf("%.2lf\n",fun2(x3));*/
printf("%2.lf",fun());
}