A、it...to play
B、this...played
C、that...playing
D、what...play
第1题:
下列给定程序中,函数fun()的功能是:根据整型参数m,计算如下公式的值。
y=1/(100×100)+1/(200×200)+1/(300×300)+…+1/(m×m)
例如,若m=2000,则应输出0.000160。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio. h>
/*************found**************/
fun (int m)
{ double y=0, d;
int i;
/*************found**************/
for (i=100, i<=m, i+=100)
{d= (double) i* (double) i;
y+=l. 0/d;
}
return (y);
}
main ( )
{ int n=2000;
clrscr();
printf("\nThe result is %lf\n",fun(n));
第2题:
下列给定程序中,函数fun()的功能是:判断一个整数m是否是素数,若是返回l,否则返回0。在main()函数中,若fun()返回1则输出YES,若fun()返回0则输出NO!
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
include <conio.h>
include <stdio.h>
int fun(int m)
{ int k=2;
while (k<=m&&(m%k))
/*************found*********************/
k++
/*************found*********************/
if(m=k)
return 1;
else return O;
}
main ( )
{ iht n;
clrscr ();
printf("\nPlease enter n: ");
scanf ("%d", &n);
if (fun (n)) printf ("YES\n");
else printf ("NO! \n");
}
第3题:
下列给定程序中,函数fun()的功能是:应用递归算法求某数a的平方根。求平方根的迭代公式如下:
例如,2的平方根为1.414214。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <math. h>
include <stdio. h>
/*************found**************/
fun(double a,double x0)
{ double xl,y;
xl= (x0+a/x0)/2.0;
/*************found**************/
if (fabs (xl-x0) >0.00001)
y=fun (a, xl);
else y=x1;
return y;
}
main ( )
{ double x;
printf("Enter x: "); scanf("%1f",&x);
printf ("The square root of %1f is %1f\n",
x, fun(x,l.O));
}
第4题:
使用VC6打开考生文件夹下的工程test12_1,此工程包含一个源程序文件test_12.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:
fun (Sample &p) 1 2
fun (Sample *p) 3 4
20 10
源程序文件test12_1清单如下:
include<iostream .h>
class Sample
{
private:
int x,y;
static int z;
public:
Sample(int a,int b){ x=a;y=b; }
void fun(Sample &p);
void fun(Sample *p);
static void print(Sample s);
};
/*************** found ***************/
int z=10;
void Sample::fun(Sample &p)
{
x=p.K;y=p.y;
cout<<"fun(Sample &p)"<<" "<<x<<" "<<y<<endl;
}
void Sample::fun(Sample *p)
{
/************** found **************/
x=p.x; y=p.y;
cout<<"fun(Sample *p) "<<" '<<x<<" "<<y<<endl;
}
void Sample::print (Sample s)
{
/*************** found *****************/
x=20;
cout<<s. x<<" "<<z<<endl;
}
void main()
{
Sample p(1,2),q(3,4);
p. fun(p);
p. fun(&q);
p. print(p);
}
第5题:
下列给定程序中,函数fun()的功能是:根据整型形参m的值,计算如下公式的值。
t=1-1/(2×2)-1/(3×3)-…-l/(m×m)
请改正函数fun()中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
double fun(int m)
{ double y=1.O;
int i;
/*************found**************/
for(i=2;i<m;i++)
/************found**************/
y-=1/ (i*i);
return(y);
}
main()
{ int n=5;
clrscr();
printf("\nThe result is %1f\n", fun(n));
}
第6题:
下列给定程序中,函数fun的功能是按以下递归公式求函数值。
例如:当给n输入5时,函数值为240;当给n输入3时,函数值为60。
请改正程序中的错误,使它能得到正确结果。
注意;不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
/*************found****+*******/
fun(int n);
{
int c;
/*************found********+*****/
if(n=1)
c=15;
else
c=fun(n-1)*2;
return(c);
}
main()
{
int n;
printf("Enter n:");
scanf("%d",&n);
printf("The result:%d\n\n",fun(n));
}