Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace PT2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- textBox1.Text = "";
- textBox2.Text = "";
- textBox3.Text = "";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string a, b, c;
- double a1, b1, c1, delta, x_1, x1_1, x2_1;
- a = textBox1.Text;
- b = textBox2.Text;
- c = textBox3.Text;
- if (textBox1.Text == "")
- {
- if(textBox2.Text == "")
- {
- if (textBox3.Text == "")
- {
- MessageBox.Show("Bạn chưa điền thông tin vào!");
- }
- }
- }
- else if(textBox2.Text == "")
- {
- a1 = Convert.ToDouble(a);
- b1 = 0;
- c1 = Convert.ToDouble(c);
- delta = System.Math.Pow(b1, 2) - 4 * a1 * c1;
- if (delta >= 0)
- {
- x1_1 = (-b1 + System.Math.Sqrt(delta)) / 2 * a1;
- x2_1 = (-b1 - System.Math.Sqrt(delta)) / 2 * a1;
- MessageBox.Show("Phương trình có 2 nghiệm phân biệt" + Environment.NewLine + "x1 = " + x1_1 + Environment.NewLine + "x2 = " + x2_1);
- }
- else if (delta == 0)
- {
- x_1 = -b1 / 2 * a1;
- MessageBox.Show("Phương trình có nghiệm kép" + Environment.NewLine + "x = " + x_1);
- }
- else
- {
- MessageBox.Show("Phương trình vô nghiệm");
- }
- }
- else if (textBox3.Text == "")
- {
- a1 = Convert.ToDouble(a);
- b1 = Convert.ToDouble(b);
- c1 = 0;
- delta = System.Math.Pow(b1, 2) - 4 * a1 * c1;
- if (delta >= 0)
- {
- x1_1 = (-b1 + System.Math.Sqrt(delta)) / 2 * a1;
- x2_1 = (-b1 - System.Math.Sqrt(delta)) / 2 * a1;
- MessageBox.Show("Phương trình có 2 nghiệm phân biệt" + Environment.NewLine + "x1 = " + x1_1 + Environment.NewLine + "x2 = " + x2_1);
- }
- else if (delta == 0)
- {
- x_1 = -b1 / 2 * a1;
- MessageBox.Show("Phương trình có nghiệm kép" + Environment.NewLine + "x = " + x_1);
- }
- else
- {
- MessageBox.Show("Phương trình vô nghiệm");
- }
- }
- else if (textBox1.Text == "0")
- {
- MessageBox.Show("a không được bằng 0");
- }
- else
- {
- a1 = Convert.ToDouble(a);
- b1 = Convert.ToDouble(b);
- c1 = Convert.ToDouble(c);
- delta = System.Math.Pow(b1, 2) - 4 * a1 * c1;
- if (delta >= 0)
- {
- x1_1 = (-b1 + System.Math.Sqrt(delta)) / 2 * a1;
- x2_1 = (-b1 - System.Math.Sqrt(delta)) / 2 * a1;
- MessageBox.Show("Phương trình có 2 nghiệm phân biệt" + Environment.NewLine + "x1 = " + x1_1 + Environment.NewLine + "x2 = " + x2_1);
- }
- else if(delta == 0)
- {
- x_1 = -b1 / 2 * a1;
- MessageBox.Show("Phương trình có nghiệm kép" + Environment.NewLine + "x = " + x_1);
- }
- else
- {
- MessageBox.Show("Phương trình vô nghiệm");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment