1.自定义函数-返回值多0.00000
//计算式子
#include<stdio.h>
#include<math.h>
float cnt(float x,float y){
y=0;
if(x<0) {printf("%.1f\t",y);}
else if(x>= 0 && x<9){
y=2*x+1;
printf("%.1f\t",y);
}else if(x>=9 && x<=100){
y = 3*x+2;
printf("%.1f\t",y);
} else if(x>100){
y = 4*x+3;
printf("%.1f\t",y);
}
return y;
}
int main(){
float a,b;
printf("please input a number:");
scanf("%f",&a);
cnt(a,b);
// printf("%f\t",b);
}
解决 --> 自定义函数定义了返回值,主函数中不需要printf.