Source Giải Phương Trình Bậc 2 bằng C#
Các bạn downlink này về giải nén rồi xem nhé! Chúc các bạn thành công.
http://www.mediafire.com/?yr32134kg31g0il
- Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GiaiPhuongTrinhBac2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
double a, b, c, x1, x2, delta, x;
a = Convert.ToDouble(txtA.Text);
b = Convert.ToDouble(txtB.Text);
c = Convert.ToDouble(txtC.Text);
if (a == 0)
{
if (b == 0)
{
if (c == 0)
{
txtKQ.Text = "Phương Trình Vô Số Nghiệm";
}
else
{
txtKQ.Text = "Phương Trình Vô Nghiệm";
}
}
else
{
x = -c / b;
txtKQ.Text = x.ToString();
}
}
else
{
delta = (b * b) - 4 * a * c;
txtDelta.Text = delta.ToString();
if (delta < 0)
{
txtKQ.Text = "Phương Trình Vô Nghiệm Vì Delta < 0";
}
else
{
if(delta == 0)
{
x = -b/(2*a);
txtKQ.Text = x.ToString();
}
else
{
x1 = (-b + Math.Sqrt(delta))/(2*a);
x2 = (-b - Math.Sqrt(delta))/(2*a);
txtKQ.Text = "Delta > 0 Phương Trình Có 2 Nghiệm";
txtx1.Text = x1.ToString();
txtx2.Text = x2.ToString();
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
txtA.Text = "";
txtB.Text = "";
txtC.Text = "";
txtDelta.Text = "";
txtKQ.Text = "";
txtx1.Text = "";
txtx2.Text = "";
}
}
}
Các bạn downlink này về giải nén rồi xem nhé! Chúc các bạn thành công.
http://www.mediafire.com/?yr32134kg31g0il