If you know the distance and the time I travelled that distance.
You just have to divide the time from the distance to get velocity
V =d
_
t
Let distance be x.
Time in going, t 1 = x/50
Time in coming, t 2 = x/40
Total time T = x/40 +x/50 = 9x/200
Average speed = total distance/ total time
=( x+x)/(9x/200)= 2x ×200/9x = 400/9 = 44.44 km/h