zorovhsvn

PT bậc 2

Aug 29th, 2015
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace PT2
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.  
  18.         private void Form1_Load(object sender, EventArgs e)
  19.         {
  20.  
  21.         }
  22.  
  23.         private void button2_Click(object sender, EventArgs e)
  24.         {
  25.             textBox1.Text = "";
  26.             textBox2.Text = "";
  27.             textBox3.Text = "";
  28.         }
  29.  
  30.         private void button1_Click(object sender, EventArgs e)
  31.         {
  32.             string a, b, c;
  33.             double a1, b1, c1, delta, x_1, x1_1, x2_1;
  34.             a = textBox1.Text;
  35.             b = textBox2.Text;
  36.             c = textBox3.Text;
  37.             if (textBox1.Text == "")
  38.             {
  39.                 if(textBox2.Text == "")
  40.                 {
  41.                     if (textBox3.Text == "")
  42.                     {
  43.                         MessageBox.Show("Bạn chưa điền thông tin vào!");
  44.                     }
  45.                 }
  46.             }
  47.             else if(textBox2.Text == "")
  48.             {
  49.                 a1 = Convert.ToDouble(a);
  50.                 b1 = 0;
  51.                 c1 = Convert.ToDouble(c);
  52.                 delta = System.Math.Pow(b1, 2) - 4 * a1 * c1;
  53.                 if (delta >= 0)
  54.                 {
  55.                     x1_1 = (-b1 + System.Math.Sqrt(delta)) / 2 * a1;
  56.                     x2_1 = (-b1 - System.Math.Sqrt(delta)) / 2 * a1;
  57.                     MessageBox.Show("Phương trình có 2 nghiệm phân biệt" + Environment.NewLine + "x1 = " + x1_1 + Environment.NewLine + "x2 = " + x2_1);
  58.                 }
  59.                 else if (delta == 0)
  60.                 {
  61.                     x_1 = -b1 / 2 * a1;
  62.                     MessageBox.Show("Phương trình có nghiệm kép" + Environment.NewLine + "x = " + x_1);
  63.                 }
  64.                 else
  65.                 {
  66.                     MessageBox.Show("Phương trình vô nghiệm");
  67.                 }
  68.             }
  69.             else if (textBox3.Text == "")
  70.             {
  71.                 a1 = Convert.ToDouble(a);
  72.                 b1 = Convert.ToDouble(b);
  73.                 c1 = 0;
  74.                 delta = System.Math.Pow(b1, 2) - 4 * a1 * c1;
  75.                 if (delta >= 0)
  76.                 {
  77.                     x1_1 = (-b1 + System.Math.Sqrt(delta)) / 2 * a1;
  78.                     x2_1 = (-b1 - System.Math.Sqrt(delta)) / 2 * a1;
  79.                     MessageBox.Show("Phương trình có 2 nghiệm phân biệt" + Environment.NewLine + "x1 = " + x1_1 + Environment.NewLine + "x2 = " + x2_1);
  80.                 }
  81.                 else if (delta == 0)
  82.                 {
  83.                     x_1 = -b1 / 2 * a1;
  84.                     MessageBox.Show("Phương trình có nghiệm kép" + Environment.NewLine + "x = " + x_1);
  85.                 }
  86.                 else
  87.                 {
  88.                     MessageBox.Show("Phương trình vô nghiệm");
  89.                 }
  90.             }
  91.             else if (textBox1.Text == "0")
  92.             {
  93.                 MessageBox.Show("a không được bằng 0");
  94.             }
  95.             else
  96.             {
  97.                 a1 = Convert.ToDouble(a);
  98.                 b1 = Convert.ToDouble(b);
  99.                 c1 = Convert.ToDouble(c);
  100.                 delta = System.Math.Pow(b1, 2) - 4 * a1 * c1;
  101.                 if (delta >= 0)
  102.                 {
  103.                     x1_1 = (-b1 + System.Math.Sqrt(delta)) / 2 * a1;
  104.                     x2_1 = (-b1 - System.Math.Sqrt(delta)) / 2 * a1;
  105.                     MessageBox.Show("Phương trình có 2 nghiệm phân biệt" + Environment.NewLine + "x1 = " + x1_1 + Environment.NewLine + "x2 = " + x2_1);
  106.                 }
  107.                 else if(delta == 0)
  108.                 {
  109.                     x_1 = -b1 / 2 * a1;
  110.                     MessageBox.Show("Phương trình có nghiệm kép" + Environment.NewLine + "x = " + x_1);
  111.                 }
  112.                 else
  113.                 {
  114.                     MessageBox.Show("Phương trình vô nghiệm");
  115.                 }
  116.             }
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment