(四)、請以 VB 遞迴程式的方式寫出一程式,可以求出x,y兩個>0整數 的最大公因數及最小公倍數。12%

詳解 (共 2 筆)

詳解 提供者:sofi1030

Function Big(a as integer,b as integer) as integer if b = 0 then Big = a else t = a mod b Big=Big(b, t) end if End Function Private Sub main() Dim x, y,small as Integer small = x * y / Big(x,y) End Sub

詳解 提供者:becky_0li

int gcd(int x,int y){ int temp; while(y!=0){ temp=x%y; x=y; y=temp; } return x; } int lcm(int a,int b){ return a*b/gcd(x,y); }