C语言第六章习题带答案
练习6-1答案
一、选择题
1.已知函数abc的定义为:
void abc()
{……}
则函数定义中void的含义是( A )。
A.执行函数abc后,函数没有返回值B.执行函数abc后,函数不再返回
C.执行函数abc后,可以返回任意类型D.以上三个答案全是错误的
2.已知:int p();,p是( C )。
A.int型变量
B.函数p的调用
C.一个函数声明,该函数的返回值是int型的值
D.强制类型转换表达式中的变量
3.以下正确的函数形式是( D )。
A.double fun(int x, int y)B.fun(int x, y)
{ z=x+y; return z; } { int z; return z; }
C.fun(x, y)D.double fun(int x, int y)
{ int x, y; double z; z=x+y; return z; } { double z; z=x+y; return z; }
4.以下说法正确的是( C )。
A.定义函数时,形参的类型说明可以放在函数体内
B.return后边的值不能为表达式
C.如果函数值的类型与返回值表达式的类型不一致,以函数值类型为准
D.如果形参与实参的类型不一致,以实参类型为准
5.C语言允许函数值类型缺省定义,此时该函数值隐含的类型是( B )。
A.float 型B.int型C.long型D.double型
6.下面函数调用语句含有实参的个数为( B )。
func((exp1, exp2), (exp3, exp4, exp5));
A.1B.2C.4D.5
7.以下程序的功能是计算函数F(x, y, z)=(x+y)/(x-y)+(z+y)/(z-y)的值,请选择填空。
#include
#include
float f(float, float);
main()
{float x, y, z, sum;
scanf("%f%f%f", &x, &y, &z);
sum=f( ①B )+f( ②C ); (注:或者选择sum=f( ①C )+f( ②B ))
printf("sum=%f\n", sum);
}
float f(float a, float b)
{float value;
value=a/b;
return(value);
}
① A.x-y, x+yB.x+y, x-yC.z+y, z-yD.z-y, z+y
② A.x-y, x+yB.x+y, x-yC.z+y, z-yD.z-y, z+y
二、填空题
8.以下程序的功能是根据输入的"y"("Y")与"n"("N"),在屏幕上分别显示出"This is YES."与"This is NO."。请填空,①是( break; )、②是( getchar() 或 getch() 或 getche() )。
#include
void YesNo(char ch)
{switch (ch)
{case 'y':
case'Y': printf("\nThis is YES.\n"); ① ;
case 'n':
case 'N': printf("\nThis is NO.\n");
}
}
main()
{char ch;
printf("\nEnter a char 'y', 'Y' or 'n', 'N':");
ch= ② ;
printf("ch:%c", ch);
YesNo(ch);
}
9.下面函数pi的功能是:根据以下公式,返回满足精度(0.0005)要求的的值,请填空,①是( t=n=1, s=0 )、②是( s*2 )。
/2=1+1/3+(1/3)*(2/5)+(1/3)*(2/5)*(3/7)+(1/3)*(2/5)*(3/7)*(4/9)+….
#include
#include
#include
double pi(double eps)
{double s, t; int n;
for ( ① ; t>eps; n++)
{s+=t;
t=n*t/(2*n+1);
}
return( ② );
}
main()
{double x;
printf("\nPlease enter a precision:");
scanf("%1f", &x);
printf("\neps=%1f, =%1f", x, pi(x));
}
三、