The individual functions have been tested separately and they give the correct output. But an appropriate main will be added, along with more comments.