c  algorithm