algorithm in c