#!/usr/bin/perl # # simple quadratic solver # copyright 2004 Pat O'Hara # licensed under the GPL print "solvequad: quadratic equation solving program by Pat O'Hara.\n\n"; print "ax^2 + bx + c\n"; print "^\n"; $a = ; chomp $a; print "ax^2 + bx + c\n"; print " ^\n"; $b = ; chomp $b; print "ax^2 + bx + c\n"; print " ^\n"; $c = ; chomp $c; $temp = $b**2 - 4*$a*$c; print "$temp\n"; if (0 > $temp){ $temp = abs $temp; $real = (-$b) / (2 * $a); print "x = $real + " . (sqrt $temp) . "i\n"; print "x = $real - " . (sqrt $temp) . "i\n"; } else{ $real = (-$b) / (2 * $a); $x1 = $real + (sqrt $temp); $x2 = $real - (sqrt $temp); print "x = $x1\n"; print "x = $x2\n"; }