Pergunta de entrevista da empresa Bosch

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