c algorithm