Implemented the function in C