Public Function solve(a, b, c) disc = b^2 - 4*a*c i = "" If disc < 0 Then i = "i" disc = -disc End If n = int(sqr(disc)) If disc <> 0 Then While (disc mod (n*n) <> 0) n = n -1 Wend disc = disc/(n*n) End If commP1 = GCF(b, 2*a) answer = "" If disc = 1 Then If i = "i" Then commAll = GCF(commP1, n) n1 = -b / commAll * sgn(a) n2 = n / commAll * sgn(a) n3 = (2*a) / commAll * sgn(a) answer = "(" & n1 & " ± " & n2 & "i)/" & n3 & " " answer = Replace(answer, " 1i", " i") answer = Replace(answer, " -1i", " -i") Else n1p = -b + n n1n = -b - n n2p = 2*a n2n = 2*a simpP = GCF(n1p, n2p) simpN = GCF(n1n, n2n) n1p = n1p / simpP * sgn(a) n1n = n1n / simpN * sgn(a) n2p = n2p / simpP * sgn(a) n2n = n2n / simpN * sgn(a) answer = n1p & "/" & n2p & " and " & n1n & "/" & n2n & " " End If ElseIf disc = 0 Then n1 = -b / commP1 * sgn(a) n2 = (2*a) / commP1 * sgn(a) answer = n1 & "/" & n2 & " " Else commAll = GCF(commP1, n) n1 = -b / commAll * sgn(a) n2 = n / commAll * sgn(a) denom = (2*a) / commAll * sgn(a) answer = "(" & n1 & " ± " & n2 & i & "√(" & disc & "))/" & denom & " " answer = Replace(answer, " 1" & i & "√", " " & i & "√") End If answer = Replace(answer, "+ -", "- ") answer = Replace(answer, "/1 ", " ") solve = answer End Function