The problem is, as n grows larger, due to floating point storage issues, the answer starts to get varied.
For example, the answer for n = 2000 is 999.944444444... but your program is giving 999.9444580. Which is clearly not correct in the first 6 decimal places. (Ref: http://ideone.com/GcdpMG)
When n is as big as 105, then the answers will be even different.
Your code throws wrong answer, because of a silly mistake. You have misplaced your printf statement. Now, what happens is, when the if statement is true, bothprintfstatements will work. Put the second one inside the body ofelse` statement. And it will give you AC.
And of course, use double to take care of precision issues.