I think the 'C' function to calculate area is flawed. You should go back to the site you obtained it from and make sure you have copied it correctly. Pay particular attention to the signs of the terms.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com