Start by working out how you would do it with a calculator. Then just convert that into C code.
If you can't do the second part, post how you would do it with a calculator and we can help you.