Pascal程式編寫問題

2008-09-26 5:16 pm
請問如何使用pascal來計算LCM?

回答 (1)

2008-09-26 10:19 pm
✔ 最佳答案
try following function lcm


program LCMPas;

function lcm(a,b:longint):longint;
var t:longint;
begin
if a<b then begin
t:=a;a:=b;b:=t;
end;
lcm:=a;
while lcm mod b>0 do inc(lcm,a);
end;

begin
write( lcm( 120, 30 ) );

end.



OK?

2008-10-03 16:39:37 補充:
RUN唔到是甚麼原因,可否詳細道來.


收錄日期: 2021-04-13 16:06:20
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20080926000051KK00277

檢視 Wayback Machine 備份