Basic algorithms in c