By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,499 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,499 IT Pros & Developers. It's quick & easy.

HELP

P: n/a
How do I write the quadratic equation in C++?
Thank You!
SonhadorPR

Aug 28 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
<so********@gmail.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.
Aug 28 '06 #2

P: n/a
so********@gmail.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.

Aug 28 '06 #3

P: n/a
<so********@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.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.
Aug 28 '06 #4

P: n/a

Jim Langston wrote:
<so********@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.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

Aug 28 '06 #5

P: n/a

"Greg" <gr****@pacbell.netwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
>
Jim Langston wrote:
><so********@gmail.comwrote in message
news:11**********************@p79g2000cwp.googleg roups.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.
Aug 28 '06 #6

P: n/a

"Jim Langston" <ta*******@rocketmail.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

Sep 11 '06 #7

P: n/a
Howard posted:
>
"Jim Langston" <ta*******@rocketmail.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
Sep 11 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.