In iOS 5, go to Settings, Store. In iOS 6, it's Settings, iTunes and App Stores.
Tap on Apple ID and you'll see a pop-up window giving you three options: View Apple ID, Sign Out and iForgot.
Tap Sign Out and you can then enter a new Apple ID and password. You can use this method to install an app using a different ID, but bear in mind that you'll need to password for the account in order to install updates for apps if you then change back to a different ID.
If you're switching IDs because you were using a shared family ID and want your own individual one, there are a couple of pitfalls to watch out for. Any purchases made the old ID will remain on the iPhone or iPad, but you'll need to enter the old ID password to get updates for those apps.
Also, if you ever reset the phone or delete apps, songs or videos bought from the iTunes store, you'll need that old ID in order to download them again.
How to create a new Apple ID
If you need a new Apple ID for any reason, you can create one online at applied.apple.com/uk. Alternatively, grab your iPhone or iPad and sign out of the ID that's currently signed in (using the instructions above) and then tap the Create New Apple ID button.