In general, it helps if you tell ALL of the pertinent parameters in your problems. Otherwise, it can be difficult to know what you used.
Here, if you just bother to look at your first expression, think about what it is doing.
n = 2;
What is 0/0 anyway? NaN.
Perhaps you need to do something special for that term. Perhaps you hoped that 0/0 might be interpreted as 1, or some other number. It is not so. In fact, it has no valid mathematical value at all, which is why NaN is returned. The fact is, 0/0 can be argued to have any value you want it to have, anything from -inf to inf, 0, NaN, 1, pi/2, take your pick from infinitely many possible values.