algorithm with c