写一个用更相减损术求最大公约数的程序
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/11 15:11:47
写一个用更相减损术求最大公约数的程序
Input m,n
If mMODn2=0 and nMOD2=0 Then
While mMOD2≠0 or nMD2≠0
m=m/2
n=n/2
Wend
Else
If m
这是高中课本上的语言语法,好像是B语言,你那个我看不懂啊,我的爪机只能补充不能追问啊,肿么办。
Input m,n
If mMODn2=0 and nMOD2=0 Then
While mMOD2≠0 or nMD2≠0
m=m/2
n=n/2
Wend
Else
If m
这是高中课本上的语言语法,好像是B语言,你那个我看不懂啊,我的爪机只能补充不能追问啊,肿么办。
这什么语言.看不懂呢.我怎么觉着它第一个循环都进不了呢.
给你看个python的辗转相除法吧,虽然语法不一样,不过思想差不多的:
print "Please input two positive integers:(each a line)"
x = int(raw_input())
y = int(raw_input())
a = max(x,y)
b = min(x,y)
while b != 0:
if a-b >= b:
a = a - b
else:
a,b = b,a-b
print "The Greatest Common Measure of the two is %d \nThe Least Common Multiple of the two is %d" % (a,x*y/a)
raw_input()
不是很喜欢basic..不过python自称..最易懂
给你看个python的辗转相除法吧,虽然语法不一样,不过思想差不多的:
print "Please input two positive integers:(each a line)"
x = int(raw_input())
y = int(raw_input())
a = max(x,y)
b = min(x,y)
while b != 0:
if a-b >= b:
a = a - b
else:
a,b = b,a-b
print "The Greatest Common Measure of the two is %d \nThe Least Common Multiple of the two is %d" % (a,x*y/a)
raw_input()
不是很喜欢basic..不过python自称..最易懂
用更相减损术求333和24的最大公约数
利用“更相减损之术”,设计一个算法,计算2136与4528的最大公约数,画出程序框图
用更相减损术求459与357的最大公约数是______.
用更相减损术求459与357的最大公约数需做多少次减法
分别用辗转相除法和更相减损术求1734和816最大公约数(写出程序)
用辗转相除法或更相减损术怎么求三个数的最大公约数
分别用辗转相除法、更相减损术求288、1995的最大公约数.
用辗转相除法或更相减损术求1890与462的最大公约数
分别用辗转相除法与更相减损术求161与253的最大公约数
分别用辗转相除法、更相减损术求204与85的最大公约数.
利用辗转相除法或更相减损术求406,232,145的最大公约数
用辗转相除法或更相减损术求下列两数的最大公约数 612,396的最大公约数