fork download
  1. using System;
  2. class Laba3
  3. {
  4. static double CalcTriangleSquareByPoints(int x1, int y1, int x2, int y2, int x3, int y3)
  5. {
  6. return Math.Abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0;
  7. }
  8. static void CalcMinOfSquares(int a, int b)
  9. {
  10. double minArea = double.MaxValue;
  11. int bestx = 0;
  12. int besty = 0;
  13. for (int x = 0; x <= a; x++)
  14. {
  15. for (int y = 0; y <= b; y++)
  16. {
  17. double area = CalcTriangleSquareByPoints(0, 0, a, b, x, y);
  18. if (area > 0 && area < minArea)
  19. {
  20. minArea = area;
  21. bestx = x;
  22. besty = y;
  23. }
  24. }
  25. }
  26. Console.WriteLine($"C = ({bestx}, {besty}), площа = {minArea}");
  27. }
  28. static void Main(string[] args)
  29. {
  30. Console.Write("Введіть a: ");
  31. int a = int.Parse(Console.ReadLine());
  32. Console.Write("Введіть b: ");
  33. int b = int.Parse(Console.ReadLine());
  34. CalcMinOfSquares(a, b);
  35. }
  36. }
Success #stdin #stdout 0.02s 27008KB
stdin
3
5
stdout
Введіть a: Введіть b: C = (1, 2), площа = 0.5