如何用pascal mod寫出計算兩個整數的公因數?

2020-10-12 11:01 pm
var num1, num2, x: integer;

begin
    writeln('Please enter the first number.');
    readln(num1);
    writeln('Please enter the second number.');
    readln(num2);
         while x <> 0 do begin   
    
    
                
                
    writeln( 'The common factor of ', num1 ,' and ', num2,' is ' , x);
end.

呢個係我盡力做到既program...有冇人可以教下我完成呢個program?

回答 (2)

2020-10-13 6:58 am
var num1, num2, x, x1, x2: integer;
begin
    writeln('Please enter the first number.'); 
    readln(num1); 
    writeln('Please enter the second number.'); 
    readln(num2);
    if 0 >= num1 or 0 >= num2 then
      writeln('numbers must be greater than 0');
      return;
    end
    x := x1 mod x2;
    while x <> 0 do begin
        x1 := x2;
        x2 := x;
        x := x1 mod x2;
    end
    writeln( 'The common factor of ', num1 ,' and ', num2,' is ' , x2); 
end.
2020-10-13 2:51 pm
睇英文電影 一開始可以睇中文字幕 過一排覺得跟到就轉英文字幕 一開始會好辛苦,但後尾你會迫自己跟到 之後再進化到冇字幕

睇英文書可以每次睇完一個Chapter講個summary畀自己聽 或者更加好就揾下班上志同道合既朋友搞個讀書會互相分享讀後心得(好有用!)

最直接就係同外國人或者ABC傾計 不過前提係要好有自信 唔怕菸先


收錄日期: 2021-04-24 08:02:46
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20201012150152AAdEExM

檢視 Wayback Machine 備份