Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _04._Distance_Between_Points
- {
- class Point
- {
- public int X { get; set; }
- public int Y { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- // Reads both points separately
- Point p1 = ReadPoint();
- Point p2 = ReadPoint();
- // Calculate the distance between them
- double distance = CalcDistance(p1, p2);
- // Print the distance
- Console.WriteLine("{0:f3}", distance);
- }
- static double CalcDistance(Point p1, Point p2)
- {
- int deltaX = p2.X - p1.X;
- int deltaY = p2.Y - p1.Y;
- return Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
- }
- static Point ReadPoint()
- {
- int[] pointInfo = Console.ReadLine().Split()
- .Select(int.Parse).ToArray();
- Point point = new Point();
- point.X = pointInfo[0];
- point.Y = pointInfo[1];
- return point;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement