Algorithm using C or C++