Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace równaniekwa
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Double a, b, c, d, x1, x2, p, q;
  13.  
  14. Console.WriteLine("Wprowadź a:");
  15. a = Convert.ToInt32(Console.ReadLine());
  16. Console.WriteLine("Wprowadź b:");
  17. b = Convert.ToInt32(Console.ReadLine());
  18. Console.WriteLine("Wprowadź c:");
  19. c = Convert.ToInt32(Console.ReadLine());
  20.  
  21. d = Math.Pow(b,2) - (4 * a * c);
  22.  
  23. p = (x1 + x2) / 2;
  24. q = -d / (4 * a);
  25.  
  26. if (d == 0)
  27. {
  28. Console.Write("Delta rowan zero\n");
  29. x1 = -b / (2.0 * a);
  30. x2 = x1;
  31. Console.Write("Pierwsza wartosc= {0}\n", x1);
  32. Console.Write("Druga wartosc= {0}\n", x2);
  33. }
  34. else if (d > 0)
  35. {
  36. Console.Write("Delta wieksza od zera\n");
  37.  
  38. x1 = (-b + Math.Sqrt(d)) / (2 * a);
  39. x2 = (-b - Math.Sqrt(d)) / (2 * a);
  40.  
  41. Console.Write("Pierwsza wartosc= {0}\n", x1);
  42. Console.Write("Druga wartosc= {0}\n", x2);
  43. }
  44. else
  45. Console.Write("Delta mniejsza od zera.\n Brak rozwiazan. \n\n");
  46.  
  47.  
  48. //Iloczynowa
  49. if (x1>0&&x2>0)
  50. {
  51. Console.WriteLine("y=" + a + "(x-" + x1 + ")(x-" + x2 + ")");
  52. }
  53. else if (x1<0&&x2>0)
  54. {
  55. Console.WriteLine("y=" + a + "(x+" + x1 + ")(x-" + x2 + ")");
  56. }
  57. else if (x1 > 0 && x2 < 0)
  58. {
  59. Console.WriteLine("y=" + a + "(x-" + x1 + ")(x+" + x2 + ")");
  60. }
  61. else
  62. Console.WriteLine("y=" + a + "(x+" + x1 + ")(x+" + x2 + ")");
  63.  
  64.  
  65. //Kanoniczna
  66. if (p>0&&q>0)
  67. {
  68. Console.WriteLine("y=" + a + "(x-" + p + ")^2+" + q);
  69. }
  70. else if (p < 0 && q > 0)
  71. {
  72. Console.WriteLine("y=" + a + "(x+" + p + ")^2+" + q);
  73. }
  74. else if (p < 0 && q < 0)
  75. {
  76. Console.WriteLine("y=" + a + "(x+" + p + ")^2-" + q);
  77. }
  78. else
  79. Console.WriteLine("y=" + a + "(x-" + p + ")^2-" + q);
  80.  
  81. Console.WriteLine("p: " + p + " q: " + q);
  82. Console.ReadKey(true);
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement