What kind of cable do I need to connect MacBook Pro to iMac for display?
If the iMac has Thunderbolt (Mid-2011 and later models):


The MBP must also have Thunderbolt
Connect the two with a Thunderbolt cable and press Cmd-F2 on the iMac's keyboard


If the iMac doesn't have Thunderbolt:


It must be a 27" model with a mini-Displayport connector (21" and 24" mini-Displayport models don't support Target Display mode).
Any device with Displayport output can use it as a display.
Connect the two with a Mini-DisplayPort to Mini-DisplayPort cable, and press Cmd-F2 on the iMac's keyboard


Full documentation is available here.