12,551,882 members (58,007 online)
Add your own
alternative version

33K views
3 bookmarked
Posted

# A simple program to solve quadratic equations with

, 11 Nov 2010 CPOL
 Rate this:
Please Sign up or sign in to vote.
A simple program to calculate quadratic equation with.Input MUST have the format:AX2 + BX + C = 0EXAMPLE: input the equation 2X2 + 4X -30 = 0 as:A= 2 B= 4 C= -30The answers for AX2 + BX + C = 0 should be 3 and -5.x1=3x2=-5 bool solver(float...
A simple program to calculate quadratic equation with.

Input MUST have the format:
AX2 + BX + C = 0

EXAMPLE: input the equation
2X2 + 4X -30 = 0 as:

A= 2 B= 4 C= -30

The answers for AX2 + BX + C = 0 should be 3 and -5.

x1=3

x2=-5

```bool solver(float a,float b, float c, float &x1, float &x2)
{
float delta = sqrt( (b*b) - (4*a*c) );

if (!a)  return false;

x1 = ( -b + delta)/(2*a);
x2 = ( -b - delta)/(2*a);

return true;
}

int main()
{
float a=2,
b=4,
c=-30;

/*
printf("a = ");
scanf("%f", &a);
printf("b = ");
scanf("%f", &b);
printf("c = ");
scanf("%f", &c);

*/

float x1,x2;
if ( solver(a, b ,c, x1, x2) ) 	printf("x1=%f\nx2=%f\n",x1,x2);

return 0;
}
```

...

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 Sweden
About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

## You may also be interested in...

 Pro Pro

## Comments and Discussions

 First Prev Next
 Reason for my vote of 1 delta can be negative a=c=1E-8 and ... vtorri15-Nov-10 19:28 vtorri 15-Nov-10 19:28
 Reason for my vote of 1 Low quality code, poor instructions ... CIDev10-Nov-10 8:43 CIDev 10-Nov-10 8:43
 Reason for my vote of 1 Is this from a 8 year old? sisira9-Nov-10 15:08 sisira 9-Nov-10 15:08
 Reason for my vote of 1 Is this from a 8 year old?
 Reason for my vote of 2 Can crash ! YvesDaoust8-Nov-10 23:26 YvesDaoust 8-Nov-10 23:26
 Reason for my vote of 1 A major problem is it doesn't preven... Andrew Phillips7-Nov-10 15:01 Andrew Phillips 7-Nov-10 15:01
 Reason for my vote of 1 There are so many things wrong with ... Saurabh.Garg6-Jun-10 20:21 Saurabh.Garg 6-Jun-10 20:21
 Last Visit: 31-Dec-99 18:00     Last Update: 24-Oct-16 0:54 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 11 Nov 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid