Login
Sign Up
Home
Program
Project
My Zone
Support
Show Code
Browse Program
Search Program
Quadratic equation solver
Input Variables
Output Variables
Program Code
Description
Variable Name *
(dynamic type)
*
!
UP
Down
Delete
Default Value *
*
Description *
*
Multi Lines
Variable Name *
(dynamic type)
*
!
UP
Down
Delete
Default Value *
*
Description *
*
Multi Lines
Variable Name *
(dynamic type)
*
!
UP
Down
Delete
Default Value *
*
Description *
*
Multi Lines
Variable Name *
(dynamic type)
*
UP
Down
Delete
Description *
*
Variable Name *
(dynamic type)
*
UP
Down
Delete
Description *
*
Input Variables List
Output Variables List
Source Code
double m = b * b - 4 * a * c; if (a == 0) { x1 = "a can not be zero"; x2 = "a can not be zero"; } else if (Math.Abs(m) < 1e-12) x1 = x2 = -b / 2 / a; else if (m > 0) { x1 = (-b + Math.Sqrt(m)) / 2 / a; x2 = (-b - Math.Sqrt(m)) / 2 / a; } else { string i; if (Math.Abs(Math.Sqrt(-m) / 2 / Math.Abs(a) - 1) < 1e-12) i = ""; else i = Convert.ToString(Math.Sqrt(-m) / 2 / Math.Abs(a)); if (b != 0) { x1 = Convert.ToString(-b / 2.0 / a) + " + " + i + "i"; x2 = Convert.ToString(-b / 2.0 / a) + " - " + i + "i"; } else { x1 = i + "i"; x2 = "-" + i + "i"; } }
Subject
Description
This program calculates the two roots of the quadratic equation:
ax
2
+ bx + c = 0
Category
Mathematics
Created By
zizo0003
Created Date
5/1/2011
Last Modify Date
5/1/2011
Calculation Count
17
Version
1.00
Positive
0
Neutral
0
Negative
0
Related Program ID
147 , 148
Copyright ©2009-2010 CUI WEI. All Rights Reserved.