首页 > 计算机等级考试
题目内容 (请给出正确答案)
[主观题]

请编一个函数float fun (double h),函数的功能是对变量h中的值保留两位小数,并对第三位进行四舍

请编一个函数float fun (double h),函数的功能是对变量h中的值保留两位小数,并对第三位进行四舍五入(规定h中的值为正数)。

例如:若h值为8.32433,则函数返回8.32:若h值为 8.32533,则函数返回8.33。

注意:部分源程序给出如下。

请勿改动主函数main 和其他函数中的任何内容,仅在函数。fun 的花括号中填入所编写的若干语句。

试题程序:

include <stdio. h>

include <conio. h>

float fun (float h )

{

}

main()

{

float a;

clrscr ();

printf ("Enter a: ");

scanf ("%f", &a);

printf("The original data is : ");

printf("%f\n\n", a) ;

printf("The result: %f\n", fun(a) );

}

查看答案
答案
收藏
如果结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能还需要:
您的账号:
发送账号密码至手机
发送
安装优题宝APP,拍照搜题省时又省心!
更多“请编一个函数float fun (double h),函数的…”相关的问题
第1题
若各选项中所有变量已正确定义,函数fun中通过return语句返回一个函数值,以下选项中错误的程序是_
_____。

A.mam() {…… x=fun(2,10); ……} fioat fun(int a,int b) { ……}

B.float fun (int a,int b) {……} main() {…… x=fun(i,j); ……}

C.float fun (int int); main() {…… x=fun(2,10); ……} float fun (int a,int b){ ……}

D.main() { float fun (int i, int j); …… x=fun(i,j); ……} float fun (int a,int b){ ……}

点击查看答案
第2题
若各选项中所用变量已正确定义,函数 fun 中通过 return 语句返回一个函数值,以下选项中错误
的程序是

A)

main()

{ …… x=fun(2,10); …… }

float fun(int a,int b){ …… }

B)

float fun(int a,int b){ …… }

main()

{ …… x=fun(i,j); …… }

C)

float fun(int,int);

main()

{ …… x=fun(2,10); …… }

float fun(int a,int b) { …… }

D)

main()

{ float fun(int i,int j);

…… x=fun(i,j); …… }

float fun(int a,int b){ …… }

点击查看答案
第3题
在同一可访问区内有如下8个函数:①doublecalculate(double x)②doublecalculate(double x, dou

在同一可访问区内有如下8个函数:

①double calculate(double x)

②double calculate(double x, double y);

③double calculate(double x. int y);

④double calculate(int x, double y);

⑤double calculate(int x);

⑥float calculate(float x);

⑦float calculate(double x);

⑧float calculate(int x,double y)。

那么关于函数重载的说法中,不正确的是(63)。

A.②③④⑤中任两个函数均构成重载

B.①③构成重载

C.②⑧肯定构成重载,⑥⑦也肯定构成重载

D.④⑧构成重载

点击查看答案
第4题
下列重载函数中,正确的是()。A.void fun(int a,float b);void fun(int c,float d)B.void fun(int

下列重载函数中,正确的是()。

A.void fun(int a,float b);void fun(int c,float d)

B.void fun(int a,float b);void fun(float a,int b)

C.float fun(int a,float b);int fun(int b,float a)

D.int fun(int a,int b);float fun(int a,int b)

点击查看答案
第5题
设fun函数的定义形式为void fun(char ch,float x){…}则下列对函数fun的调用语句中,正确的是()。A

设fun函数的定义形式为

void fun(char ch,float x){…}

则下列对函数fun的调用语句中,正确的是()。

A.A.fun("abc",3.0);

B.t=fun('D'.16.5);

C.fun('65',2.8);

D.fun(32,32);

点击查看答案
第6题
有下列函数定义:fun(float h){printf("%f,%f\n",h,h*h);}该函数的类型是()。A.int类型B.float类型

有下列函数定义: fun(float h) { printf("%f,%f\n",h,h*h);} 该函数的类型是()。

A.int类型

B.float类型

C.void类型

D.函数无类型说明,定义有错

点击查看答案
第7题
(21 )已知函数 fun 的原型为int fun (int,int,int ) ;下列重载函数原型中错误的是A ) char fun

(21 )已知函数 fun 的原型为

int fun (int,int,int ) ;

下列重载函数原型中错误的是

A ) char fun (int,int ) ;

B ) double fun (int,int,double ) ;

C ) int fun (int,char* ) ;

D ) float fun (int, int, int ) ;

点击查看答案
第8题
给定程序MODI1.C中函数fun的功能是:用下面的公式:π/4=1-1/3+1/5-1/7+.....求x的近似值,直到最后

给定程序MODI1.C中函数fun的功能是:用下面的公式:

π/4=1-1/3+1/5-1/7+.....

求x的近似值,直到最后一项的绝对值小于指定的数(参数num)为止:

例如,程序运行后,输入0.0001,则程序输出3.1414。

请改正程序中的错误,使它能输出正确的结果。_______

注意:不要改动smain函数,不得增行或删行,也不得更改程序的结构!

include 〈 math.h 〉

include 〈 stdio.h 〉

float fun (float num)

{ int s ;

float;n,t,pi ;

t=1;pi=0;n=1;s=1;

/**********found**********/

while(t 〉=num)

{

pi = pi + t ;

n = n +2 ;

s=-s ;

/**********found**********/

t = s % n ;

}

pi=pi*4 ;

return pi ;

}

main()

{ float n1,n2;

printf("Enter a float number:");

scanf("%f", &n1);

n2=fun(n1);

printf("%6.4f\n",n2);

}

点击查看答案
第9题
下列给定程序中,函数fun()的功能是;计算函数 F(x, y ,z)=(x+ y)/(x-y)+(z+ y)/(z-y)的值。其中x和

下列给定程序中,函数fun()的功能是;计算函数 F(x, y ,z)=(x+ y)/(x-y)+(z+ y)/(z-y)的值。其中x和y不相等,z和y不等。例如,当x的值为9,y的值为11,2的值为15时,函数值为-3.50。

请改正程序中的错误,使它能得出正确的结果。

注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构。

试题程序:

include <stdio. h>

include <math. h>

/**************found******************/

define FU(m, n) (m/n)

float fun(float a, float b, float c)

{ float value;

value=FU(a+ b, a-b)+FU(c+ b, c-b);

/*************found******************/

return(Value);

}

main()

{ float x, y, z, sum;

printf ("Input x y z:: ");

scanf("%f%f%f", &x, &y, &z);

printf("x=%f, y=%f, z=%f\n ",x, y, z);

if (x==y||y==z) {printf ("Data error! \n ");

exit (0); }

sum=fun (x, y, z);

printf("The result is:%5. 2f\n ",sum);

}

点击查看答案
第10题
已知函数float fun(float)是类A的成员函数,fp是指向该函数类型的指针,但fp不是类A的成员,则下列操作正确的是()

A.p=fun

B.p=fp(3.5)

C.p=A::fun

D.p=A::fun(3.5)

点击查看答案
退出 登录/注册
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改