Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. using System;
  2.  
  3. public class Program
  4. {
  5. public static void Main()
  6. {
  7.  
  8. string dana_a;
  9. string dana_b;
  10. string dana_c;
  11.  
  12.  
  13.  
  14.  
  15. Console.Write("Podaj liczbę rzeczywistą a = ");
  16. dana_a = Console.ReadLine();
  17.  
  18. Console.Write("Podaj liczbę rzeczywistą b = ");
  19. dana_b = Console.ReadLine();
  20.  
  21. Console.Write("Podaj liczbę rzeczywistą c = ");
  22. dana_c = Console.ReadLine();
  23.  
  24.  
  25. double d_a = Convert.ToDouble(dana_a);
  26. double d_b = Convert.ToDouble(dana_b);
  27. double d_c = Convert.ToDouble(dana_c);
  28. double delta = (d_b * d_b) - (4 * d_a * d_c);
  29. string delta_string = Convert.ToString(delta);
  30. Console.WriteLine();
  31. Console.WriteLine("Delta = " + delta_string);
  32. Console.WriteLine();
  33.  
  34.  
  35.  
  36. if (delta > 0)
  37. {
  38. Console.WriteLine("Pierwiastek z delty = " + Math.Sqrt(delta));
  39. Console.WriteLine();
  40. Console.WriteLine("Rozwiązania :");
  41. Console.WriteLine();
  42. double z1r = (-d_b + Math.Sqrt(delta)) / (2 * d_a);
  43. double z2r = (-d_b - Math.Sqrt(delta)) / (2 * d_a);
  44. string z1_w = Convert.ToString(z1r);
  45. string z2_w = Convert.ToString(z2r);
  46. Console.WriteLine("Pierwszy pierwiastek równania = " + z1_w);
  47. Console.WriteLine("Drugi pierwiastek równania = " + z2_w);
  48. Console.WriteLine();
  49. Console.WriteLine("Sprwadzenie :");
  50. Console.WriteLine();
  51. Console.WriteLine((d_a * z1r * z1r) + (d_b * z1r) + d_c);
  52. Console.WriteLine((d_a * z2r * z2r) + (d_b * z2r) + d_c);
  53. Console.WriteLine();
  54. }
  55. else
  56. {
  57. if (delta == 0)
  58. {
  59. Console.WriteLine("Pierwiastek z delty = " + Math.Sqrt(delta));
  60. Console.WriteLine();
  61. Console.WriteLine("Rozwiązania :");
  62. Console.WriteLine();
  63. double z1r = (d_b / (2 * d_a));
  64. string z1_w = Convert.ToString(z1r);
  65. Console.WriteLine("Pierwiastek równania wynosi = " + z1_w);
  66. Console.WriteLine("Sprawdzenie :");
  67. Console.WriteLine();
  68. dopisz sobie spr rozw xD
  69. }
  70. else
  71. {
  72. Console.WriteLine();
  73. Console.WriteLine("Pierwiastek z modułu delty = " + Math.Sqrt(Math.Abs(delta)) + " j");
  74. Console.WriteLine();
  75. Console.WriteLine("Rozwiązania :");
  76. Console.WriteLine();
  77.  
  78. double z1r = (-d_b / (2 * d_a));
  79. double z1u = (Math.Sqrt(Math.Abs(delta)) / (2 * d_a));
  80. double z2r = (-d_b / (2 * d_a));
  81. double z2u = (-Math.Sqrt(Math.Abs(delta)) / (2 * d_a));
  82. Console.WriteLine("Pierwszy pierwiastek równania = " + z1r + " + (" + z1u + ") j");
  83. Console.WriteLine("Drugi pierwiastek równania = " + z2r + " + (" + z2u + ") j");
  84. Console.WriteLine();
  85. Console.WriteLine("Sprawdzenie :");
  86. Console.WriteLine();
  87. double sRe1 = ((d_a * (z1r * z1r)) - (d_a * z1u * z1u) + d_b * z1r + d_c);
  88. double sJ1 = (2 * (d_a * z1r * z1u) + d_b * z1u);
  89. Console.WriteLine("Sprawdzenie pierwszego pierwiastka: " + sRe1 + " + (" + sJ1 + ") j");
  90. Console.WriteLine();
  91. double sRe2 = ((d_a * (z2r * z2r) - (d_a * z2u * z2u) + d_b * z2r + d_c));
  92. double sJ2 = (2 * (d_a * z2r * z2u) + d_b * z2u);
  93. Console.WriteLine("Sprawdzenie drugiego pierwsiatka: " + sRe2 + " + (" + sJ2 + ") j");
  94.  
  95. }
  96. }
  97.  
  98.  
  99. Console.WriteLine();
  100. Console.WriteLine("Wciśnięcie dowolnego klawisza spowoduje zamknięcie programu...");
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement