You open the functions.php file in a text editor.
You copy and paste the code into the file. You can leave off the <?php and ?> bits if you already have them in there.
You make sure that you don't have any blank lines or space or anything else outside of the <?php and ?> bits in the functions.php file. It needs to be pure PHP, no output at all.
You then modify your other theme files as needed.
BTW, if you don't know how PHP works, then you really should not be messing with this sort of thing anyway. Might I suggest reading some PHP tutorials online? It might help you understand what's going on. My guess is that you have added something to functions.php that causes it to have actual output, like a blank line or spaces at the beginning or end of the file. You should remove those. The file must start with <?php and end with ?> and the functions themselves, including the one you're adding, should all be in between.