Code:
#include <FPT.h>
int main()
{
double a,b,c,d,x1,x2,rp,ip ;
a = inD() ;
b = inD() ;
c = inD() ;
if (a == 0.0) {
// linear equation?
if ((b == 0.0) && (c == 0.0)) {
outS("Any number is a solution.\n") ;
} else if (b == 0.0) {
outS("There are no solutions.\n") ;
} else {
outS("There is a single real solution, ") ;
x1 = -c/b ;
outD(x1) ;
outS("\n") ;
}
} else
{
d = b*b - 4*a*c ;
if (d == 0) {
x1 = -b/(2*a) ;
outS("There are two identical real solutions, ") ;
outD(x1) ;
outS(" and ") ;
outD(x1) ;
outS("\n") ;
} else if (d > 0) {
d = sqrt(d) ;
x1 = (-b + d)/(2*a) ;
x2 = (-b - d)/(2*a) ;
outS("There are two real solutions, ") ;
outD(x1) ;
outS(" and ") ;
outD(x2) ;
outS("\n") ;
} else {
d = sqrt(-d) ;
rp = -b/(2*a) ;
ip = d/(2*a) ;
outS("There are two complex answers, ") ;
outD(rp) ;
if (ip >= 0) {
outS(" + ") ;
outD(ip) ;
outS("i") ;
} else {
outS(" - ") ;
outD(-ip) ;
outS("i") ;
}
outS(" and ") ;
ip = -ip ;
outD(rp) ;
if (ip >= 0) {
outS(" + ") ;
outD(ip) ;
outS("i") ;
} else {
outS(" - ") ;
outD(-ip) ;
outS("i") ;
}
outS("\n") ;
}
}
}
I believe that i got a working program! Someone shoot me some numbers so that i know it solves all numbers!