fun(float x) { float y; y=3*x-4; return y; }以上函数值的类型为什么是int?怎么不是float呢?

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/27 03:39:07
fun(float x) { float y; y=3*x-4; return y; }以上函数值的类型为什么是int?怎么不是float呢?

fun(float x) { float y; y=3*x-4; return y; }以上函数值的类型为什么是int?怎么不是float呢?
fun(float x) { float y; y=3*x-4; return y; }
以上函数值的类型为什么是int?怎么不是float呢?

fun(float x) { float y; y=3*x-4; return y; }以上函数值的类型为什么是int?怎么不是float呢?
y的是int,因为你定义函数的时候没定义函数返回值的类型,所以默认fun函数的返回值类型为int,相当于:
int fun(float x)
{
float y;
y=3*x-4;
return y;
}
即使你在函数内定义的y的类型为float型,但是由于你的y是返回值,且返回值的类型是int,所以系统会进行自动转换,所以函数值的类型是int.如果你要函数值类型为float,则要在定义函数的时候定义函数的类型,即:
float fun(float x)
{
float y;
y=3*x-4;
return y;
}
即使不定义函数类型时自动默认为int,但是一般还是加上函数类型的好.

float 第二步float fun(float x)定义了一个函数,这个函数自变量是什么?即float x为第二步float fun(float x)定义了一个函数,这个函数自变量是什么?即float x为什么不写成x? // void fun( float y ,float x[],) { x[0] = x[1] + x[2]; y = y + x[3] ; fun(float x) { float y; y=3*x-4; return y; }以上函数值的类型为什么是int?怎么不是float呢? 以下函数值的类型是 fun ( float x ) { float y; y= 3*x-4; return y; } 以下函数值的类型是( ).fun ( float x ) { float y; y= 3*x-4; return y; } 以下函数值的类型是fun ( float x ){ float y;y= 3*x-4;return y;} c语言用梯形法求积分#include float integral(float(*fun)(float x),float a,float b,int,n) {float s,h,y; int i; s=(fun(a)+fun(b))/2; h=(b-a)/n; for(i=1;i float (*p)(float)是什么意思 请问以下函数值的类型fun(float x){float y;y=3*x-4;return y;}书上的答案是int型的,请问是为什么? integral(float(*f)(float a,float 设有如下函数 fun (float x) { printf(\n%d,x*x); } 则函数的类型是 float是什么意思 float market float x=2 if (x #include #include #include int fun(float x[],int n) /f#include #include #include int fun(float x[],int n)//if(x[j]=>xa)c++;return ;}main(){float x[100]={193.199f,195.673f,195.757f,196.051f,196.092f,196.596f,196.579f,196.763f};system(cls);printf(%d #include#includevoid fun(float *p1,float *p2,float *s){s=(float *)calloc(1,sizeof(float));*s=*p1+*p2++;}int main(){float a[2]={1.1,2.2},b[2]={10.0,20.0},*s=a;fun(a,b,s);printf(%5.2f ,*s);}为什么输出是1.10,求解fun到底发生了什么 求x^3-15x^2+16x-80一个实根,下面程序怎么算不出来#include#includefloat f(float x){return ((x-5)*x-16)*x-80;}float xpoint(float x1,float x2){return (x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));}float root(float x1,float x2){float x,y,y1;y1=f(x1);do{