I assumed that points (x1,y1) and (x2,y2) where the closest for the initial conditions then I'm trying to set up the algorithm to systematically check the distance of all the other pairs of point and then switch those with (x1,y1) and (x2,y2) if they were found to be closer.
!Let a and b be the two closest sets of points. PROGRAM Coordinates IMPLICIT NONE REAL :: x1,y1,x2,y2,xk,yk,dist,xn,yn INTEGER :: a,b,n,k PRINT *, “Enter the number of points and the coordinates of these points" READ *, k, x1,y1, x2,y2,,,,xk,yk,xn,yn IF(k<=2 .OR. k=>1000)THEN PRINT *, “The number of points to be considered must be between 2 and 1000) ELSE a=(x1,y1) b=(x2,y2) k=1 DO WHILE(k=>2 .OR. k<=1000) READ *, xk,yk,xn,yn IF(sqrt((x2-x1)**2+(y2-y1)**2))<=sqrt((xk-xn)**2-(yk-yn)**2))THEN PRINT *, “The points (x1,y1) and (x2,y2) are the two closest points” ELSE IF(sqrt((xk-xn)**2-(yk-yn)**2)<=sqrt(x2-x1)**2+(y2-y1)**2))THEN a=(xk,yk) b=(xn,yn) k=k+1 n=n+1 ENDDO ENDIF PRINT *, “the two closest points are”, a, “and”, b ENDPROGRAM Coordinates
The issue is that i'm unsure whether the (xk,yk) and (xn,yn) setup will work where x and k are two arbitrary values such that the algorithim moves on and reads the next two points until it has exhausted all possible combinations of points, is there a better way to write this if this doesn't work?