//---------------------------------------------------------------------------
/* 最大公倍数 */
int Euclid(int A, int B) {
  if (B == 0)
    return A;
  else return Euclid(B, A % B);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int I;
  I = Euclid(StrToIntDef(Edit1->Text, 0), StrToIntDef(Edit2->Text, 0));
  if (I == 0) return;
  Edit1->Text = IntToStr(StrToIntDef(Edit1->Text, 0) / I);
  Edit2->Text = IntToStr(StrToIntDef(Edit2->Text, 0) / I);
}
//---------------------------------------------------------------------------

解决方案 »

  1.   

    function Euclid(A, B: Integer): Integer; { 最大公倍数 }
    begin
      if B = 0 then
        Result := A
      else Result := Euclid(B, A mod B);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
      I := Euclid(StrToIntDef(Edit1.Text, 0), StrToIntDef(Edit2.Text, 0));
      if I = 0 then Exit;
      Edit1.Text := IntToStr(StrToIntDef(Edit1.Text, 0) div I);
      Edit2.Text := IntToStr(StrToIntDef(Edit2.Text, 0) div I);
    end;
      

  2.   

    嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻
    嘻嘻嘻知道了吧嘻嘻嘻嘻
    嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻procedure TForm1.Button1Click(Sender: TObject);
    var
      A, B, I: Integer;
    begin
      A := StrToIntDef(Copy(Edit1.Text, 1, Pos(':', Edit1.Text) - 1), 0);
      B := StrToIntDef(Copy(Edit1.Text, Pos(':', Edit1.Text) + 1, MaxInt), 0);
      I := Euclid(A, B);
      if I = 0 then Exit;
      A := A div I;
      B := B div I;
      Caption := Format('%d:%d', [A, B]);
    end;
      

  3.   

    是最在最大公約數,不是最大公倍數.
    你們是怎麼搞的.
    To: v_lucky(Lucky) 
       至於有沒有這要的必要,我想在有的時候民必需這樣做的.