small improvement to second solution in C