Pages

Make a program in C# that find the value of X by using quadratic formula.


CODE:

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace ConsoleApplication4
{
classProgram
    {
staticvoid Main(string[] args)
        {
double a, b, c, y,X1, X2;
Console.WriteLine("please enter a");
            a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("please enter b");
            b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("please enter c");
            c = Convert.ToDouble(Console.ReadLine());
            y = Math.Sqrt((b * b) - (4 * a * c));
            X1 = ((-1) * (b) + y) / (2 * a);
            X2 = ((-1) * (b) - y) / (2 * a);
Console.WriteLine("the value of X1 is {0}",X1);
Console.WriteLine("the value of X2 is {0}", X2);
        }
    }
}


 OUTPUT:


ALGORITHM:

  • ·         Start:
  • ·         Initializing: double a, b, c, y, X1, X2,
  • ·         Output: please enter a
  • ·         Set a: Taking input from the user
  • ·         Output: please enter b
  • ·         Set b:Taking input from the user
  • ·         Output: please enter c
  • ·         Set c: Taking input from the user
  • ·         Set y: square root of {(b * b) - (4 * a * c)}
  • ·         Set X1: {(-1) * (b) + y} / (2 * a)
  • ·         Set X2: {(-1) * (b) - y} / (2 * a)
  • ·         Output: Result
  • ·         End.

No comments:

Post a Comment