Algorithm for c language sparse matrix