VelizarAvramov

08. Center Point

Nov 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _08._Center_Point
  4. {
  5.     class CenterPoint
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double x1 = double.Parse(Console.ReadLine());
  10.             double y1 = double.Parse(Console.ReadLine());
  11.             double x2 = double.Parse(Console.ReadLine());
  12.             double y2 = double.Parse(Console.ReadLine());
  13.  
  14.             string result = FindClosesPoint(x1, x2, y1, y2);
  15.             if (result == "first")
  16.             {
  17.                 Console.WriteLine($"({x1}, {y1})");
  18.             }
  19.             else
  20.             {
  21.                 Console.WriteLine($"({x2}, {y2})");
  22.             }
  23.         }
  24.  
  25.         private static string FindClosesPoint(double x1, double x2, double y1, double y2)
  26.         {
  27.             double diagonal1 = Math.Sqrt(x1 * x1 + y1 * y1);
  28.             double diagonal2 = Math.Sqrt(x2 * x2 + y2 * y2);
  29.             if (diagonal1 <= diagonal2)
  30.             {
  31.                 return "first";
  32.             }
  33.             else
  34.             {
  35.                 return "second";
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment