algorithm code in c language, for leaning purpose.