Advertisement
Guest User

abc333

a guest
Nov 26th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int a, b, c, x;
  14. // Console.WriteLine("Введіть коєф. рівняння");
  15. string[] o = Console.ReadLine().Split(' ');
  16. a = Convert.ToInt32(o[0]);
  17. b = Convert.ToInt32(o[1]);
  18. c = Convert.ToInt32(o[2]);
  19. //Console.WriteLine("Ви задали рівняння:{0}x*x+{1}x+{2}=0", a, b, c);
  20. int d = b * b - 4 * a * c;
  21. //Console.WriteLine("Дискримінант = " + d);
  22. if (d > 0)
  23. {
  24. double x1, x2;
  25. x1 = (-b + Math.Sqrt(d)) / (2 * a);
  26. x2 = (-b - Math.Sqrt(d)) / (2 * a);
  27. if (x1 > x2)
  28. {
  29. Console.WriteLine("Two roots: " + x2 + " " + x1);
  30. }
  31. else
  32. {
  33. Console.WriteLine("Two roots: " + x1 + " " + x2);
  34.  
  35. }
  36. //Console.WriteLine("One roots: " + x1);
  37. //Console.WriteLine("Two roots: " + x2);
  38. }
  39. else if(d==0)
  40. {
  41. x = (-b / (2 * a));
  42. Console.WriteLine("One root: " + x);
  43. }
  44. else
  45. {
  46. Console.WriteLine("No roots");
  47. }
  48. Console.ReadLine();
  49.  
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement