Geshi
In general the Geshi library is a popular library for formatting code ( http://qbnz.com/highlighter/)
Geshi as a WordPress plugin
For WordPress several authors “packaged” Geshi in a plugin. take your pick:
http://wordpress.org/extend/plugins/search.php?q=geshi
The one I use
Personally I use this plugin: http://wordpress.org/extend/plugins/codecolorer/. This one works by enclosing all pieces of codes with a [cc lang=”bla”] code [/cc] tag where you can specify things like language, width, line numbering, etc…