Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Local $n = InputBox("Endless Love", "Enter the numerator of the fraction:")
- Local $d = InputBox("Endless Love", "Enter the denominator of the fraction:")
- If $d = 0 Then Exit MsgBox(0x10, "Error", "Denominator can't be zero!")
- _ReduceFraction($n, $d)
- MsgBox(0, "Endless Love", "Reduced fraction: " & ($n==0 ? $n : $n & "/" & $d))
- ; Reduce a fraction
- Func _ReduceFraction(ByRef $iNumerator, ByRef $iDenominator)
- Local $iGCD = _GCD($iNumerator, $iDenominator)
- $iNumerator /= $iGCD
- $iDenominator /= $iGCD
- If $iDenominator < 0 Then
- $iNumerator = -$iNumerator
- $iDenominator = -$iDenominator
- EndIf
- EndFunc
- ; Calculate the Greatest Common Divisor of $a and $b
- Func _GCD($a, $b)
- $a = Abs($a)
- $b = Abs($b)
- If ($a = 0 Or $b = 0) Then Return $a + $b
- While ($a <> $b)
- If $a > $b Then
- $a -= $b
- Else
- $b -= $a
- EndIf
- WEnd
- Return $a
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment