Time until distance gets equal to X between two objects moving in opposite direction | C ++ implementation of the approach ; Function to return the time for which the two policemen can communicate ; time = distance / speed ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double getTime ( int u , int v , int x ) { double speed = u + v ; double time = x / speed ; return time ; } int main ( ) { double u = 3 , v = 3 , x = 3 ; cout << getTime ( u , v , x ) ; return 0 ; }