Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. public partial class MainWindow : Window
  2. {
  3. public MainWindow()
  4. {
  5. InitializeComponent();
  6. }
  7. double Delta(double a, double b, double c)
  8. {
  9. return b * b - 4 * a * c;
  10. }
  11. public void Pierwiastki(double a, double b, double c, out double x1, out double x2)
  12. {
  13. if (Delta(a, b, c) == 0)
  14. {
  15. x1 = (-b) / (2 * a);
  16. x2 = 0;
  17. }
  18. else
  19. {
  20. x1 = ((-b) - (Math.Sqrt(Delta(a, b, c)))) / (2 * a);
  21. x2= ((-b) + (Math.Sqrt(Delta(a, b, c)))) / (2 * a);
  22. }
  23.  
  24.  
  25.  
  26. }
  27. private void btn1_Click(object sender, RoutedEventArgs e)
  28. {
  29. double a = Convert.ToDouble(txtA.Text);
  30. double b = Convert.ToDouble(txtB.Text);
  31. double c = Convert.ToDouble(txtC.Text);
  32. double x1, x2;
  33. Pierwiastki(a, b, c,out x1,out x2);
  34. lblWynik.Content = x1.ToString("F2");
  35. lblWynik.Content = x2.ToString("F2");
  36.  
  37. }
  38.  
  39.  
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement