程序填空题(共15题)
1、在考生文件夹下,给定程序FILL.C的功能是:
求二分之一的圆面积,函数通过形参得到圆的半径,函数返回二分之一的圆面积(注意:圆面积公式为:S=3.14159*r*r,在程序中定义的变量名要与公式的变量相同)。例如,输入圆的半径值:2.5,输出为s=9.817469。
#include
/************found************/
double fun ( float r) double fun ( float ___1___ )
double fun ( float r)
{
return 3.14159 * r*r/2.0 ;
}
main()
{
float x;
printf ( "Enter x: ");
scanf ( "%f", &x);
scanf ( "%f", &x);
scanf ( "%f", ___2___ );
printf (" s = %f\n ", fun ( x ) );
}
2、在考生文件夹下,给定程序FILL.C的功能是:
计算并输出下列级数的前n项之和Sn,直到Sn大于q为止,q的值通过形参传入。
Sn = 2/1 + 3/2 + 4/3 + …… + (n+1)/n
例如,若q的值为50.0,则函数值为50.416691。
#include
float fun( float q )
{
int n;
float s;
n = 2;
s = 2.0;
/************found************/
while(s<=q) while (s___1___q)
while(s<=q)
{
s=s+(float)(n+1)/n;
/************found************/
n++; ___2___;
n++;
}
return s;
}
main()
{
printf("%f\n", fun(50));
}
3、在考生文件夹下,给定程序FILL.C的功能是:
统计整数n的各个位上出现数字1、2、3的次数,并通过外部(全局)变量c1、c2、c3返回主函数。
例如,当n=123114350时,结果应该为:c1=3 c2=1 c3=2。
#include
int c1,c2,c3;
void fun(long n)
{
c1 = c2 = c3 = 0;
while (n)
{
switch(n%10) /************found************/
switch(n%10)
switch(___1___)
{
case 1: c1++; break;
/************found************/
break; case 2: c2++;___2___;
break;
case 3: c3++;
}
n /= 10;
}
}
main()
{
int n=123114350;
fun(n);
printf("\nn=%d c1=%d c2=%d c3=%d\n",n,c1,c2,c3); }
4、在考生文件夹下,给定程序FILL.C的功能是:
程序的功能是计算y = 0! + 1! + 2! + 3! + 4! + …… + n! 如输入n的值为5的话,则输出y值为154
#include
int fun(int n)
{
int i;
int s;
s=1;
for (i=1; i<=n; i++)
/************found************/
s=s*i; s=___1___;
s=s*i;
return s;
}
main()
{
int s;
int k,n;
scanf("%d",&n);
s=0;
for (k=0; k<=n; k++)
/**********