If ABCD is a square having coordinates A (4, 5), B (4, 1) and C (8, 1), the coordinates of D are
(8,5)
If ABCD is a square the midpoints of the diagonals will be same.
So midpoints of AC and BD is the same.
Midpoint of the line joining two points A (x1,y1) and B (x2,y2) is (x1+x22, y1+y22)
Midpoint of AC is (6, 3).
Midpoint of BD is also the same.
So using the above formula we get the coordinates of D as (8, 5).