Advertisement
dxnge

Untitled

Oct 1st, 2022 (edited)
1,029
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. using System.Security.Cryptography.X509Certificates;
  5.  
  6. namespace ConsoleApp4
  7. {
  8.     internal class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<List<int>> list = new List<List<int>>();
  13.             List<double> dist = new List<double>();
  14.             Console.WriteLine("how many points?");
  15.             int n = Convert.ToInt32(Console.ReadLine());
  16.             for (int i = 1; i <= n; i++)
  17.             {
  18.                 Console.Write($"x{i}: ");
  19.                 int x = Convert.ToInt32(Console.ReadLine());
  20.                 Console.Write($"y{i}: ");
  21.                 int y = Convert.ToInt32(Console.ReadLine());
  22.                 List<int> crds = new List<int>() {x, y};
  23.                 list.Add(crds);
  24.             }
  25.             foreach (List<int> i in list)
  26.             {
  27.                 int x= i[0], y = i[1];
  28.                 double s = Math.Pow(Math.Pow(x, 2) + Math.Pow(y, 2), 0.5);
  29.                 dist.Add(s);
  30.             }
  31.  
  32.             Console.WriteLine($"n{dist.IndexOf(dist.Min()) + 1}, len == {dist.Min()}");
  33.         }
  34.     }
  35.  
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement