fork download
  1. using System;
  2.  
  3. public class Program
  4. {
  5. static double CalcMinOfSquares(int bx, int by)
  6. {
  7. double min_square = double.MaxValue;
  8. int min_x = 0;
  9. int min_y = 0;
  10. for (int cx = 0; cx <= bx; cx++)
  11. {
  12. for (int cy = 0; cy <= by; cy++)
  13. {
  14. double tsquare = CalcTriangleSquareByPoints(0, 0, bx, by, cx, cy);
  15. if (tsquare > 0 && tsquare < min_square)
  16. {
  17. min_square = tsquare;
  18. min_x = cx;
  19. min_y = cy;
  20. }
  21. }
  22. }
  23. Console.WriteLine($"Координати C: ({min_x}; {min_y})");
  24. return min_square;
  25. }
  26. static double CalcTriangleSquareByPoints(int ax, int ay, int bx, int by, int cx, int cy)
  27. {
  28. return 0.5 * Math.Abs(ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
  29. }
  30. static void Main(string[] args)
  31. {
  32. Console.WriteLine("Введіть значення x: ");
  33. int bx = int.Parse(Console.ReadLine());
  34. Console.WriteLine("Введіть значення y: ");
  35. int by = int.Parse(Console.ReadLine());
  36. if (bx <= 0 || by <= 0)
  37. {
  38. Console.WriteLine("Потрібно ввести додатні числа");
  39. return;
  40. }
  41. double tsquare = CalcMinOfSquares(bx, by);
  42. Console.WriteLine($"Мінімальна площа трикутника: {tsquare}");
  43. }
  44. }
Success #stdin #stdout 0.06s 9556KB
stdin
4219
1023
stdout
Введіть значення x: 
Введіть значення y: 
Координати C: (598; 145)
Мінімальна площа трикутника: 0.5