11-05-2024, 04:04 PM
Well @Petr I gotta give you credit for your approach: factor both numbers find the factors in common. It would be how I would do it, like Steve did for reducing fractions. So I had to share this way I learned years ago.
Simplifying fractions is just as easy!
Simplifying fractions is just as easy!
Code: (Select All)
_Define A-Z As INTEGER
While 1
Input "Enter fraction to simplify as n/d, 0 quits "; fraction$
slash = InStr(1, fraction$, "/")
n = Val(Mid$(fraction$, 1, slash - 1))
d = Val(Mid$(fraction$, slash + 1))
If slash = 0 Or n = 0 Or d = 0 Then End
g = gcd(n, d): sn = n / g: sd = d / g
Print n; "/"; d; " simplifies to "; sn; "/"; sd
Print
Wend
Function gcd (a, b)
'a and b will be changed unless make copies
c = a: d = b
While c <> 0 And d <> 0
If c > d Then c = c Mod d Else d = d Mod c
Wend
gcd = c + d
End Function
b = b + ...