Advertisement
fbinnzhivko

Point on Segment

Mar 16th, 2016
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. class PointOnSegment
  3. {
  4.     static void Main()
  5.     {
  6.         var first = double.Parse(Console.ReadLine());
  7.         var second = double.Parse(Console.ReadLine());
  8.         var point = double.Parse(Console.ReadLine());
  9.  
  10.         var left = Math.Min(first, second);
  11.         var right = Math.Max(first, second);
  12.         var leftDistance = Math.Abs(point - left);
  13.         var rightDistance = Math.Abs(point - right);
  14.         var distance = Math.Min(leftDistance, rightDistance);
  15.  
  16.         if (point >= left && point <= right)
  17.         {
  18.             Console.WriteLine("in\n{0}", distance);
  19.         }
  20.         else
  21.         {
  22.             Console.WriteLine("out\n{0}", distance);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement