Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SoftUniiii
- {
- class Program
- {
- static double Dist(Point pa, Point pb)
- {
- double dist = Math.Sqrt(Math.Pow(pa.X - pb.X, 2) + Math.Pow(pa.Y - pb.Y, 2));
- return dist;
- }
- static void Main(string[] args)
- {
- Console.Write("Enter n: ");
- int n = int.Parse(Console.ReadLine());
- Random rand = new Random();
- Point[] points = new Point[n];
- for (int i = 0; i < n; i++)
- {
- Console.Write("x: ");
- int x = int.Parse(Console.ReadLine());
- Console.Write("y: ");
- int y = int.Parse(Console.ReadLine());
- points[i] = new Point(x, y);
- }
- Console.WriteLine("Random distance: " + Dist(points[rand.Next(n)], points[rand.Next(n)]));
- double minDist = double.MaxValue;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (i == j)
- {
- continue;
- }
- double currentDist = Dist(points[i], points[j]);
- if (currentDist < minDist)
- {
- minDist = currentDist;
- }
- }
- }
- Console.WriteLine($"Min distance = {minDist}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement