You can usually write simple programs that will do this for simple pieces of code. For "C" and "Fortran" there are functions for this called CForm and Fortran form. Usually the easiest way to do this is to call these functions and to make whatever minor adjustments distinguish the language you are using.
Alternatively, for more complicated computations, you might consider using the EmbedCode function.