added c implementation of algorightm