Hi,
I'm trying to calculate the minimum distance between 2 closest in an array and I don't know why my program won't run - can someone please help?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise
{
public class Program
{
static int Main(string[] args)
{
int n = 0;
int[] FirstArray = new int[n];
Random r = new Random();
int Minimum = int.MaxValue;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (Minimum > Math.Abs(FirstArray - FirstArray[j]))
{
Minimum = Math.Abs(FirstArray - FirstArray[j]);
}
}
Console.WriteLine("Minimum = {0}", Minimum);
Console.Read();
return 0;
}
}
class Elements
{
public double Distance(Elements compar)
{
var x1 = Convert.ToDouble(Console.ReadLine());
var y1 = Convert.ToDouble(Console.ReadLine());
var x2 = Convert.ToDouble(Console.ReadLine());
var y2 = Convert.ToDouble(Console.ReadLine());
var finalResult = Distance(x1, x2, y1, y2);
}
private static double Distance(double x1, double x2, double y1, double y2)
{
var temp1 = Math.Pow((x2 - x1), 2);
var temp2 = Math.Pow((y2 - y1), 2);
var result = Math.Sqrt(temp1 + temp2);
return result;
}
}
}
}
I'm trying to calculate the minimum distance between 2 closest in an array and I don't know why my program won't run - can someone please help?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise
{
public class Program
{
static int Main(string[] args)
{
int n = 0;
int[] FirstArray = new int[n];
Random r = new Random();
int Minimum = int.MaxValue;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - 1; j++)
{
if (Minimum > Math.Abs(FirstArray - FirstArray[j]))
{
Minimum = Math.Abs(FirstArray - FirstArray[j]);
}
}
Console.WriteLine("Minimum = {0}", Minimum);
Console.Read();
return 0;
}
}
class Elements
{
public double Distance(Elements compar)
{
var x1 = Convert.ToDouble(Console.ReadLine());
var y1 = Convert.ToDouble(Console.ReadLine());
var x2 = Convert.ToDouble(Console.ReadLine());
var y2 = Convert.ToDouble(Console.ReadLine());
var finalResult = Distance(x1, x2, y1, y2);
}
private static double Distance(double x1, double x2, double y1, double y2)
{
var temp1 = Math.Pow((x2 - x1), 2);
var temp2 = Math.Pow((y2 - y1), 2);
var result = Math.Sqrt(temp1 + temp2);
return result;
}
}
}
}