Firstly, got to the Settings App on your device and tap your name at the top.
Now scroll down to the bottom until you see the Sign Out option, displayed in red.
Click Sign Out and you will then need to enter your password that is linked with your Apple ID.
After you have entered your password, click the Turn Off option. After that, do not keep a copy of any information on your iPhone and then click Sign Out.
A confirmation message will appear to ensure you want to remove iCloud, click Sign Out.
Following the above steps should remove your iCloud account from your iPhone/iPad.