Function that calculates diffrent positions from an array c# -
i have problem need solving. im supposed create function calculates distance between 2 positions. positions stored in 2 arrays, can use many parameters need calculation
static double[] latitudes = new double[] { 59.3261917, 57.7010496, 59.8939529, 65.5867395, 60.11021, 52.5069312, 48.859 }; static double[] longitudes = new double[] { 17.7018773, 11.6136602, 10.6450348, 22.0422998, 24.7385057, 13.1445521, 2.2069765 };
i have been given equation me calculate distance
distance = math.sqrt( (x1 - x2)2 + (y1 - y2)2 )
my problem can't elements arrays variables inside function
show dictance pairs
if (latitudes.length == longitudes.length) { (int = 0; < latitudes.length - 1; = + 2) { double x1 = longitudes[i]; double x2 = longitudes[i + 1]; double y1 = latitudes[i]; double y2 = latitudes[i + 1]; double distance = math.sqrt(math.pow(x1 - x2, 2) + math.pow(y1 - y2, 2)); console.writeline($"x1 = {x1}; x2 = {x2}; y1 = {y1}; y2 = {y2}; distance {distance}"); } }
Comments
Post a Comment