The Euclidean algorithm is used to find the greatest common divisor (gcd) of two positive integers
(继续)a and b.
input (a)
input (b)
while b>0
begin
r:=a mod b
a:=b
b:=r
end
gcd:=a
output(gcd)
When the algorithm is used to find the greatest common divisor of a =273 and b=110, which of the following is the sequence of computed values for r?
(A)2,26,1,0
(B)2,53,1,0
(C)53,2,1,0
(D)53,4,1,0
(E) 53,5,1,0
选D,怎么做的?
程序里的":="是什么意思?
人气:451 ℃ 时间:2020-03-29 14:30:31
解答
这是求最大公约数的算法,在这个程序中":="应该就是赋值号,就是把符号右边变量的值赋给左边变量,mod是取余的函数,循环语句中
第一次 a=273 ,b=110 ,a/b的余数r=53
第二次 a=110 ,b=53 ,r=4
第三次 a=53 ,b=4 ,r=1
第四次 a= 4 ,b=1 ,r=0
因而r 的取值为 D
推荐
猜你喜欢
- 如图所示,物体处于平衡状态,若保持a不变,当力F与水平方向夹角β多大时F有最小值( ) A.β=0 B.β=π2 C.β=α D.β=2α
- 人体呼出的氮气和吸入氮气含量有没有发生变化
- 一台座钟,它的分针长5厘米.这台座钟的分针的针端一天所走的路程是多少米?
- 滑轮组可以省力,改变用力方向,不能同时省力又省距离
- 若直线l1:y=k(x-4)与直线l2关于点(2,1)对称,则l2直线恒过点(0,2).(0,2)点怎么算的?
- 英语翻译
- 那个男孩比班上任何一个学生都高.That boy is ( )( )( )( )in the class.
- 如图:四边形ABCD为菱形,对角线AC=8,BD=6,对角线相交于点O,P是边AD上一点(P与D点可重合)