using System.Collections.Generic;
private List<double> roots = new List<double>();
public QuadraticEq(int pa, int pb, int pc)
public double[] GetRealRoots()
if(this.Discriminant > 0)
Console.WriteLine("{0}x^2 + {1}x + {2} has 2 roots", a, b, c);
roots.Add( (-b + Math.Sqrt(this.Discriminant)) / (2*a));
roots.Add( (-b - Math.Sqrt(this.Discriminant)) / (2*a));
else if (this.Discriminant == 0)
Console.WriteLine("{0}x^2 + {1}x + {2} has 1 roots", a, b, c);
Console.WriteLine("{0}x^2 + {1}x + {2} has 0 roots", a, b, c);
public override string ToString()
return a + "x^2 +" + b + "x +" + c;
public static void Main()
QuadraticEq q = new QuadraticEq(2,7,2);
Console.WriteLine("d = {0}", q.Discriminant);
double[] results = q.GetRealRoots();
foreach (double x in results)
Console.WriteLine("Equation is {0}",q);