I'm trying to write a c# program code to find the min distance between the closest numbers in an array and my c# program won't work? -
i'm having problems c# code calculating min distance between 2 closest numbers in array - can please help!! program trying pick random numbers , generate array , array j. finally, trying determine min distance between 2 closest numbers in array. don't know why won't provide output.
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; (int = 0; < n; i++) { (int j = 0; j < n - 1; j++) { if (minimum > math.abs(firstarray[i] - firstarray[j])) { minimum = math.abs(firstarray[i] - 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; } } }
}
two tips here
at line 8 : length of firstarray '0'.
you don't give value firstarray.
Comments
Post a Comment