Bosch Interview Question

Come up with a solution to this problem using C and C++.