program untuk menghitung akar persamaan ax^2 + bx + c

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PersamaanAkarKuadrat
{
    class Program
    {
        static double hitung(double a, double b, double c)
        {
            double d, x1, x2;
            d = x1 = x2 = 0;
            d = Math.Sqrt(Math.Pow(b, 2) - 4 * a * c);
            x1 = (-b + d) / (2 * a);
            x2 = (-b - d) / (2 * a);
            Console.WriteLine("Akar persamaan 1 = x1 = " + x1);
            Console.WriteLine("Akar persamaan 2 = x2 = " + x2);
            return 0;
        }

        static string tanda(double angka)
        {
            if (angka >= 0)
                return "+";
            else
                return "";
        }

        static void Main(string[] args)
        {
            double a, b, c;
            Console.WriteLine("PROGRAM MENGHITUNG AKAR PERSAMAAN KUADRAT");
            Console.WriteLine("==============================================================================");
            Console.WriteLine("Bentuk Persamaan = ax^2 + bx + c");
            Console.Write("Masukkan nilai a = "); a = double.Parse(Console.ReadLine());
            Console.Write("Masukkan nilai b = "); b = double.Parse(Console.ReadLine());
            Console.Write("Masukkan nilai c = "); c = double.Parse(Console.ReadLine());
            Console.WriteLine("---------------------------------------------------");
            Console.Write("Bentuk Persamaannya menjadi = ");
            Console.WriteLine("{0}x^2 {1}{2}x {3} {4}", a, tanda(b), b, tanda(c), c);
            hitung(a,b,c);
            Console.Read();
        }
    }
}

Komentar