Advertisement
StoyanGrigorov

Untitled

Oct 10th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. //04. Distance between Points
  5. namespace DistanceBetweenPoints
  6. {
  7.     class DistanceBetweenPoints
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Point p1 = Point.GetPoint();
  12.                         //Защо не става само с Point p1 = GetPoint();
  13.             Point p2 = Point.GetPoint();
  14.             double distance = Point.CalculateDistance(p1, p2);
  15.             Console.WriteLine(distance);
  16.  
  17.         }
  18.     }
  19.  
  20.     public class Point
  21.     {
  22.         public double x { get; set; }
  23.         public double y { get; set; }
  24.  
  25.         public static Point GetPoint()
  26.         {
  27.             double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray();
  28.             Point point = new Point() { x = input[0], y = input[1] };
  29.             return point;
  30.         }
  31.  
  32.         public static double CalculateDistance(Point p1, Point p2)
  33.         {
  34.             double deltaX = p1.x - p2.x;
  35.             double deltaY = p1.y - p2.y;
  36.             double distance = Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2));
  37.             return distance;
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement