Form1.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace _01_1_TestKontrolek
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void btnOblicz_Click(object sender, EventArgs e)
  19. {
  20. double a = double.Parse(tbA.Text);
  21. double b = double.Parse(tbB.Text);
  22. double c = double.Parse(tbC.Text);
  23. double delta = b * b - 4 * a * c;
  24. //if (delta < 0)
  25. // label1.Text = "Brak rozwiązań!\r\n(delta = "+ delta.ToString() +")";
  26. if (delta < 0)
  27. label1.Text = $"Brak rozwiązań!\r\n(delta = {delta})";
  28. else if (delta == 0)
  29. label1.Text = $"Jedno rozwiązanie: x0 = {-b / (2 * a)}";
  30. else
  31. {
  32. double x1 = (-b - Math.Sqrt(delta)) / (2 * a);
  33. double x2 = (-b + Math.Sqrt(delta)) / (2 * a);
  34. label1.Text = $"Dwa rozwiązania:\r\n x1 = {x1}\r\n x2 = {x2}";
  35. }
  36. }
  37. }
  38. }