Advertisement
ivandrofly

Quadratic Solver - C-Sharp

Jul 28th, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using System;
  2.  
  3. namespace QuadraticSolverSharp
  4. {
  5.     public static class Solver
  6.     {
  7.         public static Tuple<double, double> QuadraticFormula(double a, double b, double c)
  8.         {
  9.             // Compute the discriminant
  10.             // /\ = b^2 - 4ac
  11.             double disc = Math.Pow(b, 2) - 4 * a * c;
  12.  
  13.             // Compute the two roots
  14.             double root1 = (-b + Math.Sqrt(disc)) / (2 * a);
  15.             double root2 = (-b - Math.Sqrt(disc)) / (2 * a);
  16.  
  17.             return new Tuple<double, double>(root1, root2);
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement