求两数的最大公约数
function gcd(a,b:integer):integer;
第1题:
( 22 )下面是求最大公约数的函数的首部
Function gcd ( ByVal x As Integer, ByVal y As Integer ) As Integer
若要输出 8 、 12 、 16 这 3 个数的最大公约数,下面正确的语句是
A ) Print gcd ( 8,12 ) , gcd ( 12,16 ) , gcd ( 16,8 )
B ) Print gcd ( 8 , 12 , 16 )
C ) Print gcd ( 8 ) , gcd ( 12 ) , gcd ( 16 )
D ) Print gcd ( 8 , gcd ( 12,16 ))
第2题:
单击命令按钮时,下列程序代码的执行结果为( )。 Private Function FirProc(x As Integer,y As Integer,z As Integer) FirProc=2*x+y+3*z End Funcfion Private Function SecProc(x As Integer,y As Integer,z As Integer) SecProc=FirProc(z,x,y)+x End Funcfion Private Sub Command1_Click() Dim a As Integer Dim b As Integer Dim c As Integer a=2 b=3 c=4 Printf SecProc(c,b,a) End Sub
A.21
B.19
C.17
D.34
第3题:
下面是求最大公约数的函数的首部Function gcd(ByVal x As Integer,ByVal y As Integer)As Integer若要输出8、12、16这3个数的最大公约数,下面正确的语句是
A.Print ged(8,12),gcd(12,16),gcd(16,8)
B.Print ged(8,12,16)
C.Print gcd(8),gcd(12),gcd(16)
D.Print gcd(8,gcd(12,16))
第4题:
单击命令按钮时,下列程序的执行结果是 Private Sub Command1_Click() Dim a As Integer,b As Integer,C As Integer a=3 b=4 c=5 Print SecProc(c,b,A)End Sub Function FirProc (x As Integer,y As Integer,z As Integer) FirProc=2 * x + y + 3 * z+2 End Function Function SecProc (x As Integer,y As hteger,z As Integer) SecProc=FirProc(z,x,y)+x+7 End Function
A.20
B.25
C.37
D.32
第5题:
单击命令按钮时,下列程序代码的执行结果为 ( ) Function FirProc(x As Integer, y As Integer, z As Integer) FirProc=2*x+y+3*z End Function Function SecProc(x As Integer, y As Integer, z As Integer) SecProc=FirProc(z, x, y)+x End Function Private Sub Commandl Click() Dim a As Integer, b As Integer, c As Integer a=2 :b=3 :c=4 Print SecProc(c, b,A)End Sub
A.21
B.19
C.17
D.34
第6题:
设有以下函数过程: Function fun(a As Integer,b As Integer) Dim c As Integer If a<b Then c=a:a=b:b=C End IF c=0 Do c=c+a Loop Until c Mod b=0 fun=c End Function 若调用函数fun时的实际参数都是自然数,则函数返回的是( )。
A.a、b的最大公约数
B.a、b的最小公倍数
C.a除以b的余数
D.a除以b的商的整数部分
第7题:
下列子过程语句中正确的是( )。
A.Sub f1(ByVal() As Integer)
B.Sub f1(n() As Integer)As Integer
C.Function f1(f1 As Integer)As Integer
D.Function f1(ByVa1 f as Integer)
第8题:
求两数的最小公倍数
function lcm(a,b:integer):integer;
begin
if a<b then swap(a,b);
lcm:=a;
while lcm mod b>0 do inc(lcm,a);
end;
第9题:
折半查找
function binsearch(k:keytype):integer;
var low,hig,mid:integer;
begin
low:=1;hig:=n;
mid:=(low+hig) div 2;
while (a[mid].key<>k) and (low<=hig) do begin
if a[mid].key>k then hig:=mid-1
else low:=mid+1;
mid:=(low+hig) div 2;
end;
if low>hig then mid:=0;
binsearch:=mid;
end;
第10题:
下面4个CT函数中是用来判断用户输入的数是否为奇数的,是奇数的返回1,否则返回0,其中正确的是
A.Function CT(ByVal a As Integer) If a Mod 2=0 Then Return 0 ElSe Return 1 End if End Function
B.Function CT(ByVal a As Integer) If a Mod 2=0 Then CT=0 Else CT=1 End if End Function
C.Function CT(ByVal a As Integer) If a Mod 2=0 Then CT=1 Else CT=0 End if End Function
D.Function CT(ByVal a As Integer) If a Mod 2=0 Then Return 1 Else Return 0 End if End Function
第11题:
单击命令按钮时,下列程序代码的执行结果为______。 Private Function FirProc (x As Integer,y As Integer,z As Integer) FirProc=2*x+y+3*z End Function Private Function SecProc(x As Integer,y As Integer,z As Integer) SecProc=FirProc(z,x,y)+x End Function Private Sub Command1_Click() Dim a As Integer Dim b As Integer Dim C As Integer a=2 b = 3 c = 4 Print SecProc(c,b,A) End Sub
A. 21
B.19
C.17
D.34
第12题:
单击命令按钮时,下列程序的执行结果是 Private Sub Command1_Click() Dim a As Integer, b As Integer, c As Integer a=3:b :4:c =5 Print SecProc ( c, b,A)End Sub Function FirProc(x As Integer, y As Integer, z As Integer) FirProc:2 * x + y + 3 * z+2 End Function Function SecProc( x As Integer, y As Integer, z As Integer) SecProc = FirProc ( z, x, y) + x + 7 End Function
A.20
B.25
C.37
D.32
第13题:
下列程序运行后,单击命令按钮,窗体显示的结果为( )。 Private Function pl(x As Integer,y As Integer,z As Integer) pl=2*x+y+3*z End Function Private Function p2(X As Integer,y As Integer,z As Integer) p2=p1(z,y,x)+x End Function Private Sub Commandl_Click()
A.23
B.19
C.21
D.22
第14题:
下列子过程语句中正确的是 A.Sub f1(By Val()As Integer) B.Sub f1(n()As Integer)As Integer C.Function f1(f1 As Integer)As Integer D.Function f1(By Val f As Integer)
第15题:
单击命令按钮时,下列程序的执行结果为 Private Sub Command1_Click() Dim a As Integer,b As Integer,c As Integer a=2:b=3:C=4 Print P2(c,b,A)End Sub Private Function P1(x As Integer,y As Integer,z As Integer) P1=2 * X + y + 3 * z End Function Private Function P2(x As Integer,y As Integer,z As Integer) P2=P1(z,x,y) + X End Function
A.21
B.19
C.17
D.34
第16题:
下列过程语句中正确的是( )。
A.Sub fl(By Val () As Integer)
B.Sub fl(n() As Integer)As Integer
C.Function fl(fl As Integer)As Integer
D.Function fl(By Val f As Integer)
第17题:
单击一次窗体之后,下列程序代码的执行结果为______。 Private Sub Command1_ Click() Dim a As Integer, b As Integer, c As Integer a = 1: b = 2: c = 4 Print Value(a, b,C)End Sub Function Num(x As Integer, y As Integer, z As Integer) Num = x * x + y * y + z * z End Function Function Value(x As Integer, y As Integer, z As Integer) Value = Num(x, y, z) + 2 * x End Function
A.21
B.23
C.19
D.35
第18题:
在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程: Private Sub Command1_Click () Dim a As Integer, b As Integer, c As Integer a = 1: b = 2: c = 3 Print fun2 (c, b,A)End Sub Private Function funl (x As Integer, y As Integer, z As Integer) fun1 = 2 * x + y + 3 * z End Function Private Function fun2(x As Integer, y As Integer, z As Integer) fun2 = fun1(z, x, y)+ x End Function程序运行后,单击命令按钮,则窗体上显示的内容是
A.7
B.14
C.17
D.30
第19题:
下面是求最大公约数的函数的首部( )。 Function fun(By Val x As integer.ByVal Y As Integer)As Integer 若要输出8、12、16这3个数的最大公约数,下面正确的语句是
A. Print fun(8,12),fun(12,16),fun(16,8)
B. Prilit fun(8,12,16)
C. print fun (8,12),fun(12,16),fun(16)
D. Print fun(8,fun(12,16))
第20题:
素数的求法
A.小范围内判断一个数是否为质数:
function prime (n: integer): Boolean;
var I: integer;
begin
for I:=2 to trunc(sqrt(n)) do
if n mod I=0 then begin
prime:=false; exit;
end;
prime:=true;
end;
第21题:
以下程序运行后,单击命令按钮,窗体显示的结果是 ______。 Private Function p1(x As Integer,y As Integel,z As Integer) p1=2*x+y+3*z End Function Private Function p2(x As Integer,y As Integer,z As Integer) p2=p1(2,y,x)+x End Function Private SubCommandl_Click() Dim a As Integer Dim b As Integer Dim c As Integer a=2:b=3:c=4 Print p2(c,b,A)
End Sub
A.19
B.21
C.22
D.23
第22题:
下面是求最大公约数的函数的首部: Function gcd(ByVal X As Integer,ByVal y As Integer)As Integer 若要输出8、12、16这3个数的最大公约数,下面正确的语句是( )。
A.Print gcd(8,12),gcd(12,16),gcd(16,8)
B.Print gcd(8,12,16)
C.Print gcd(8),gcd(12),gcd(16)
D.Print gcd(8,gcd(12,16))
第23题:
设有以下函数过程:
Function fun(a As Integer,b As Integer)
Dim c As Integer
If a<b Then
c=a:a=b:b=C
End IF
c=0
Do
c=c+a
Loop Until c Mod b=0
fun=c
End Function
若调用函数fun时的实际参数都是自然数,则函数返回的是( )。
A.a、b的最大公约数
B.a、b的最小公倍数
C.a除以b的余数
D.a除以b的商的整数部分
B。【解析】本题考查了Do Loop循环,实现的是最小公倍数。本题中If语句实现了a和b交换。