imaginary number in c++

could someone help me on what to input on C++ so that i can get the imaginary roots of a quadratic equation....
I really don't know what to do...😭
help me please..😕😕😭
thank you!!

Replies

  • vinci
    vinci
    [​IMG]
    try this equation. let me know if it doesnt work still
  • silverscorpion
    silverscorpion
    Use 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...
  • maria flor
    maria flor
    vinci
    [​IMG]
    try this equation. let me know if it doesnt work still
    it doesn't work
  • maria flor
    maria flor
    silverscorpion
    Use 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...
    i just tried it but when i try to input an equation with imaginary roots.. it doesn't give me an answer...
  • maria flor
    maria flor
    silverscorpion
    Use 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...
    thanks for that but when i try to input an equation with imaginary roots.. it still doesn't give an answer...
  • silverscorpion
    silverscorpion
    After 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 "<Try using this..
                                        
  • vinci
    vinci
    you need value of of a,b,c ?i found that equation i posted here gives complex roots .
  • maria flor
    maria flor
    silverscorpion
    After 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 "<Try using this..
    it still don't work... when i try to run it and input values with imaginary roots it suddenly return...
  • silverscorpion
    silverscorpion
    What is the input you are giving and what is the output?

    Give the full dump..
  • maria flor
    maria flor
    here: when i input those numbers...it returns without giving any roots...

You are reading an archived discussion.

Related Posts

technical paper writing is a new concept for me... plz tell me abt it or giv me sum directions .... how can a present a paper at clg level...
What is SAP and How to learn it..! Can I learn it online ?
Guys, Indian Hockey (Women) have put a brilliant performance kudos to them for they have earned it. Its a proud moment for Indians. Wishing them good luck for comming matches......
Hello guys If you know any web designer in Personal then Please ask him to contact me I am in great need of him Designer will be paid on the...
Hello guys, I am working on modeling a tire in NX I-Deas. I am stuck on the part where I have to extrude on tire curved surface. I don't know...