HELP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sonhadorPR@gmail.com

    #1

    HELP

    How do I write the quadratic equation in C++?
    Thank You!
    SonhadorPR

  • osmium

    #2
    Re: HELP

    <sonhadorPR@gma il.comwrote:
    How do I write the quadratic equation in C++?
    The same way you write any other equation in C++. Do the algebra with
    pencil and paper (if necessary) and type in the equation following the rules
    of the language.


    Comment

    • red floyd

      #3
      Re: HELP

      sonhadorPR@gmai l.com wrote:
      How do I write the quadratic equation in C++?
      Thank You!
      SonhadorPR
      >
      Send me your instructor's email address, and I'll send it directly to him.

      Comment

      • Jim Langston

        #4
        Re: HELP

        <sonhadorPR@gma il.comwrote in message
        news:1156735467 .326839.112140@ p79g2000cwp.goo glegroups.com.. .
        How do I write the quadratic equation in C++?
        Thank You!
        SonhadorPR
        Quadradic Equation is
        ax^2 + bx + c = 0 (where ^2 is squared).

        For x this becomes:

        -b +/- Sqrt( b^2 - 4ac )
        x = ------------------------
        2a

        Which is known as the Quadratic Formula.

        In C or C++ langauge terms this is:
        x = (-b + sqrt( b*b - 4 * a * c ) ) / 2 * a;
        x = (-b - sqrt( b*b - 4 * a * c ) ) / 2 * a;

        (Yes, there are two possible answers.


        Comment

        • Greg

          #5
          Re: HELP


          Jim Langston wrote:
          <sonhadorPR@gma il.comwrote in message
          news:1156735467 .326839.112140@ p79g2000cwp.goo glegroups.com.. .
          How do I write the quadratic equation in C++?
          Thank You!
          SonhadorPR
          >
          Quadradic Equation is
          ax^2 + bx + c = 0 (where ^2 is squared).
          >
          For x this becomes:
          >
          -b +/- Sqrt( b^2 - 4ac )
          x = ------------------------
          2a
          >
          Which is known as the Quadratic Formula.
          >
          In C or C++ langauge terms this is:
          x = (-b + sqrt( b*b - 4 * a * c ) ) / 2 * a;
          x = (-b - sqrt( b*b - 4 * a * c ) ) / 2 * a;
          >
          (Yes, there are two possible answers.
          More precisely: there are at most two solutions to the equation.
          Depending on the inputs, there may be two, one or no solutions for a
          particular equation. The somewhat tricky part is to make sure that the
          program can handle all three of these outcomes.

          Greg

          Comment

          • Jim Langston

            #6
            Re: HELP


            "Greg" <greghe@pacbell .netwrote in message
            news:1156740277 .976827.220010@ p79g2000cwp.goo glegroups.com.. .
            >
            Jim Langston wrote:
            ><sonhadorPR@gm ail.comwrote in message
            >news:115673546 7.326839.112140 @p79g2000cwp.go oglegroups.com. ..
            How do I write the quadratic equation in C++?
            Thank You!
            SonhadorPR
            >>
            >Quadradic Equation is
            >ax^2 + bx + c = 0 (where ^2 is squared).
            >>
            >For x this becomes:
            >>
            > -b +/- Sqrt( b^2 - 4ac )
            >x = ------------------------
            > 2a
            >>
            >Which is known as the Quadratic Formula.
            >>
            >In C or C++ langauge terms this is:
            >x = (-b + sqrt( b*b - 4 * a * c ) ) / 2 * a;
            >x = (-b - sqrt( b*b - 4 * a * c ) ) / 2 * a;
            >>
            >(Yes, there are two possible answers.
            >
            More precisely: there are at most two solutions to the equation.
            Depending on the inputs, there may be two, one or no solutions for a
            particular equation. The somewhat tricky part is to make sure that the
            program can handle all three of these outcomes.
            >
            Greg
            True. a == 0.0 would cause problems.


            Comment

            • Howard

              #7
              Re: HELP


              "Jim Langston" <tazmaster@rock etmail.comwrote in message news:aAtIg.33
              >
              In C or C++ langauge terms this is:
              x = (-b + sqrt( b*b - 4 * a * c ) ) / 2 * a;
              x = (-b - sqrt( b*b - 4 * a * c ) ) / 2 * a;
              >
              Don't you need parentheses there, around the "2 * a" part? Division and
              multiplication have the same precedence, so as written, the above would
              divide by 2, then multiply by a, instead of dividing by (2 * a), right?

              -Howard



              Comment

              • Frederick Gotham

                #8
                Re: HELP

                Howard posted:
                >
                "Jim Langston" <tazmaster@rock etmail.comwrote in message news:aAtIg.33
                >>
                >In C or C++ langauge terms this is:
                >x = (-b + sqrt( b*b - 4 * a * c ) ) / 2 * a;
                >x = (-b - sqrt( b*b - 4 * a * c ) ) / 2 * a;
                >>
                >
                Don't you need parentheses there, around the "2 * a" part? Division and
                multiplication have the same precedence, so as written, the above would
                divide by 2, then multiply by a, instead of dividing by (2 * a), right?

                Yes Howard, you're correct.

                The formulae should be:

                (-b + sqrt(b*b - 4*a*c)) / (2*a);
                (-b - sqrt(b*b - 4*a*c)) / (2*a);

                --

                Frederick Gotham

                Comment

                Working...