there are several ways of doing this. But the first question is, what kind of representation you have?
One way of doing this is to use the gaussian elimination on the matrix. That way you got an complexity with O(n^3) in a fairly easy way.
If you already have a way to calculate the determinant of a matrix (which you proberbly could use to test if a matrix even is invertible; Not all are! But gaussian does the test too..) you can use the equation
IIRC the inverse of a matrix is an unstable operation with many caveats when implementing it. I'm guessing that if you need the inverse you might also need more matrix operations and thats why i'd advise you to use a library. If on the other hand the sole purpose is to practice creating this operation then follow the links above.
Then there's http://sourceforge.net/apps/wordpress/itpp/ but not sure how well it handles matrices but it certainly has support for them. It also uses syntax very similar to MATLAB when creating and manipulating data.