Thursday, 2 May 2013

How to make calculate quadratic formula in c#

How to make calculate quadratic formula in c#
Object


Write a program which takes two variables a, b and constant c as input from the user to calculate roots using quadratic formula. It must include two functions to return the calculated roots. 
  
Code


    class program1
    {
        Public static double root(double a, double b, double c)
        {


            double re = -b + System.Math.Sqrt(b * b) - (4 * a * c) / (2 * a);

           return re;

        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ///////////////////////////first//////////////////////////////

            double a, b, c;
            double res = 0;
            Console.WriteLine("Enter a value");
            a = double.Parse(Console.ReadLine());
            Console.WriteLine("Enter B value");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("Enter c Value");
            c = double.Parse(Console.ReadLine());

           
            res = pogram.root(a, b, c);
            Console.WriteLine("Quadratic Answer is ::" + res);


Screen Shot

No comments:

Post a Comment