Why You Should Avoid Using pow() for Integer Exponentiation

When i run this code in Vscode on windows machine it give wrong output at 153 & 1741725.

Enter the number 153 sum is 152. 153 is not an Armstrong number but exception — its gives right output on macos machine vs code.

Here, is the snapshot of my vs code:

I Learned this now: pow() is not your friend. Do not use it for integer powers. Especially do not use it if you depend on getting exact integer results. Use pow() only when nothing else will do.

Even if the result of the exponentiation you want to perform is exactly representable as a double, the general-purpose exponentiation approach taken by that function might compute a result that differs ever so slightly. When you convert the result to an integer, the fractional part is truncated. That's ok for you if there is an error away from zero, but if there is even a single-bit error towards zero then the subsequent integer conversion will produce a result that is off by one.

Here, is the corrected code:

HOPE, IT HELPS!