How are games created for different platforms?
For example, Call of Duty: Modern Warfare 3 is available on PS3, Xbox 360, Wii and PC.
Are they completely reprogrammed with no common code? Is there any intermediate code?
Most production level game engines have what is known as a Hardware Abstraction Layer. This is a generic API that the game engine can use to talk with hardware with out having to know which hardware that is. They just call SoundManager.PlaySFX(SFX_ID) or the like. Underneath in the sound manager however it will know which hardware its actually working on and make the appropriate calls to get the sound effect to play.
This allows the engine to be developed using that layer of abstraction so it can run on any system provided an API is provided for that hardware that matches the abstraction. EDIT: As noted by Johnathan, an API for each platform you want to run on is required. And to Trevor's point, when moving from a high memory system to a low memory (Worst for me was PS3 to PSP) you may have to tackle the different hardware limitations. Luckily for me I have not had to rewrite an entire system because of a platform, but I have had to go through and optimize objects to take up less of a foot print.
The other side of things is in the art area where resolutions of textures or models and the like are different. The assets of the game can be built towards a specific target so a PC gets its wav files for its sound effects while they are turned into the specific formats that the PS3 support and the like.
Hope this helps.
The other answers spell things out in the ideal cases. Most code is common for games, and a clean abstraction layer is used for hardware/platform dependent parts.
However, many games have ports done by an outsourced company, and code diverges significantly. This is especially true with the consoles, but also common of ports to OSX or Linux from Windows.
On consoles, the hardware is different enough that often entire chunks of the core rendering (and rarely also other systems) must be completely rewritten. On the PC you can jut abstract over D3D and OpenGL, as the OS APIs differ but all the PC hardware is roughly the same.
On the console space, you might find that your super efficient gorgeous rendering engine is outright impossible to port directly over to a different console, since the GPU capabilities are so different and you literally need to squeeze out every last percentage of performance to get 7 year old hardware to run your modern game. You can easily find cases where the lighting passss that work best on the XBox are horrendously slow on the PS3, and where the best approach on the PS3 dogs on the XBox. The other hardware and platform differences (eg the SPUs on the PS3 vs the tri-core CPU of the XBox) make it very difficult to rely on a simple thin hardware abstraction layer as your only platform-dependent code path.
Since each platform also requires an extensive amount of expertise to utilize it properly, many games require a specialized outsourced porting company to bring the game to additional platforms. In the PC space you can sometimes find solo developers who do the ports (like Ryan "icculus" Gordon who does many Linux game ports; straight forward work usually, changing D3D to GL and Win32 to POSIX/SDL), while in the console space there are companies with all teams to do rather massive porting work to larger games.
Ports to some platforms do require almost complete rewrites or asset redesigns. The Wii ports of Call of Duty for instance where done by an outsourced company, and everything - including the art assets - had to be redone to fit within the constraints of the Wii's very limited hardware. The Wii doesn't even have shaders, for instance, so simply reusing the same engine and effects/materials was outright impossible, and the limited memory and CPU/GPU required smaller textures and less details models, plus gameplay limitations and so on. Ports to mobile platforms likewise are typically entirely rewritten, usually by a third party.
Newer engines make it easier to port between platforms, but larger games typically still need to update sizable portions of their code and redo many assets to change from more capable PC platforms and consoles to more restricted platforms.
James reponse only relates to PC and not for the implementation on the specific platforms.