algorithm implementation in C==