imaginary number in c++
I really don't know what to do...😭
help me please..😕😕😭
thank you!!
Member • Feb 25, 2012
Member • Feb 25, 2012
Member • Feb 25, 2012
it doesn't workvinci
try this equation. let me know if it doesnt work still
Member • Feb 25, 2012
i just tried it but when i try to input an equation with imaginary roots.. it doesn't give me an answer...silverscorpionUse a variable to indicate whether the delta (B[sup]2[/sup]-4AC) is positive or negative.
Instead of
pro = sqrt((b*b)-(4*a*c));
here, use
pro = sqrt(abs(B*B)-(4*A*C))
And then, if delta is positive, use it as is. If delta is negative, just print an 'i' or 'j' along with the result, to indicate that the root is imaginary...
Member • Feb 25, 2012
thanks for that but when i try to input an equation with imaginary roots.. it still doesn't give an answer...silverscorpionUse a variable to indicate whether the delta (B[sup]2[/sup]-4AC) is positive or negative.
Instead of
pro = sqrt((b*b)-(4*a*c));
here, use
pro = sqrt(abs(B*B)-(4*A*C))
And then, if delta is positive, use it as is. If delta is negative, just print an 'i' or 'j' along with the result, to indicate that the root is imaginary...
Member • Feb 25, 2012
pro = sqrt(abs(B*B-4*A*C)) if ((B*B-4*A*C) >= 0) { x1 = (-B+pro)/2*A x2 = (-B-pro)/2*A cout << "The first root is " << x1 << endl cout << "The second root is " << x2 << endl } else { real = -B/2*A imag = pro/2*A cout << "The first root is "<<real<<"+i"<<imag<<endl cout << "The first root is "<<real<<"-i"<<imag<<endl }Try using this..
Member • Feb 25, 2012
Member • Feb 25, 2012
it still don't work... when i try to run it and input values with imaginary roots it suddenly return...silverscorpionAfter you have calculated delta, (variable "pro" in your program), calculate the individual roots in the following way..
pro = sqrt(abs(B*B-4*A*C)) if ((B*B-4*A*C) >= 0) { x1 = (-B+pro)/2*A x2 = (-B-pro)/2*A cout << "The first root is " << x1 << endl cout << "The second root is " << x2 << endl } else { real = -B/2*A imag = pro/2*A cout << "The first root is "<<real<<"+i"<<imag<<endl cout << "The first root is "<<real<<"-i"<<imag<<endl }Try using this..
Member • Feb 25, 2012
Member • Feb 26, 2012