How To Solve Quadratic Equation In C#
C# is a language that was made by Microsoft it is almost as the replica of Java it contains a lot of build in function to make the programming development rapid .C# is mostly used in Desktop Applications like Windows Form , Windows Presentation Foundation (WPF) , Universal Windows Presentation Foundation (UWPF) and also in Website we use ASP.net .Now to calculate quadratic equation we need to know the formula of quadratic equation which is .
Now by looking at the formula we can use it an start development i will use classes and function to build this application now lets build the class
public class Quadratic
{
public double a, b, c;
public double underRoot;
public double x;
public Quadratic()
{
this.a = 0.0f;
this.b = 0.0f;
this.c = 0.0f;
this.x = 0.0f;
this.underRoot = 0.0f;
}
public void positiveQuadratic(double a, double b, double c)
{
underRoot = (b * b - 4 * a * c);
if(underRoot==0)
{
Console.Write("Not Possiable");
}
else
{
double xyz=Math.Sqrt(underRoot);
x = ((-b + xyz) / (2 * a));
Console.WriteLine(x);
}
}
public void negitiveQuadratic(double a, double b, double c)
{
underRoot = (b * b - 4 * a * c);
if (underRoot == 0)
{
Console.Write("Not Possiable");
}
else
{
double xyz = Math.Sqrt(underRoot);
x = ((-b - xyz) / (2 * a));
Console.WriteLine(x);
}
}
}
public static void Main(string[] args)
{
Quadratic q1 = new Quadratic();
q1.positiveQuadratic(2, -8, -24);
q1.negitiveQuadratic(2, -8, -24);
}
}
Now lets break this down the line double xyz=Math.Sqrt(underRoot); means take the square root of this variable and save it in the variable named xyz .We used two functions because you cannot calculate the positive and negative sides at the same time so we needed two functions for this purpose.And why i used f in these statement this.a = 0.0f; because C# doesn't recognize double and float variables we have to put f at the last to tell that this is a float type or double type .
Conclusion
So today we just learned how to make a quadratic equation calculator in C# console application .IF you run into some errors please let me know other wise thanks for coming.
Comments
Post a Comment