本帖最后由 3mile 于 2010-7-23 14:04 编辑
好吧,改进一下Local $x, $y, $j, $Result
Dim $input = InputBox("", "车棚有车65辆,输入车轮总数")
$divisor = Common_divisor(2, 3)
If $input >= 130 And $input<=205 Then
If Mod($input, $divisor) <> 0 Then
MsgBox(4096, "警告", "车轮数不符" & @CRLF & "请检查数据")
Else
If IsInt(Execute($input)) Then
For $x = 0 To $input / 2
For $y = 0 To $input / 3
$j = $x *2+ $y*3
If $j = $input And $x+$y=65 Then
$Result &= "自行车有:" & $x & "辆" & @TAB & "三轮车有:" & $y & "辆" & @CRLF
EndIf
Next
Next
MsgBox(0, 0, $Result)
Else
MsgBox(4096, "警告", "车轮残缺不全" & @CRLF & "不予计算")
EndIf
EndIf
Else
MsgBox(4096, "警告", "车棚内无独轮车"&@CRLF&"无三轮以上的车" & @CRLF & "不予计算")
EndIf
Func Common_divisor($num1, $num2);计算公倍数
Dim $a = $num1, $b = $num2
While 1
$temp = Mod($a, $b)
$a = $b
$b = $temp
If $b = 0 Then ExitLoop
WEnd
;此时$a是公约数
Return $num1 * $num2 / $a;返回公倍数
EndFunc ;==>Common_divisor
|