Thread: quadratic formula in c

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    36

    quadratic formula in c

    so i need to find the real roots after entering an a b and c for the quadratic formula....i basically have it except when i type in lets say 3 2 1 it says -1.#ind0....i have read that this is because there is some kind of math error...i dont know if i necessary want to post my code because i know my classmates use this website...would it be valid to say

    [code]

    if ( a > b && a > c)
    printf("there are no real roots.\n")

    [\code]

    this might be more of a math question but i thought i would take a shot

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    36
    nevermind haha i got it

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    For those who might look at this question and wonder about the answer:

    Given a quadratic equation of the form 0 = ax^2 + bx + c, you must first look at the discriminant, d = b^2 - 4ac, before you go ahead and solve it.

    If d > 0, there are two real roots:
    x1 = (-b + sqrt(d))/2a
    x2 = (-b - sqrt8d))/2a

    If d = 0, there is one real root:
    x = -b/2a

    And if d < 0, there are no real roots, but 2 complex roots:
    x1 = -b/2a + i * sqrt(-d)/2a)
    x2 = -b/2a - i * sqrt(-d)/2a)
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with quadratic formula functions
    By orikon in forum C++ Programming
    Replies: 10
    Last Post: 10-15-2005, 04:49 PM
  2. Help on quadratic formula DOS program
    By blankstare77 in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2005, 08:57 PM
  3. how to change char to formula
    By kosong in forum C Programming
    Replies: 2
    Last Post: 06-09-2003, 04:31 AM
  4. Formula string conversion
    By Gr3g in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 08:28 PM
  5. Quadratic Equation Program
    By Ambizzy in forum C Programming
    Replies: 4
    Last Post: 02-19-2002, 09:21 PM