Skip to content
Advertisement

how to find 2 to the power of n . n ranges from 0 to 200

Assume my system as 32 bit machine. Considering this if I use long int for n>63 I will get my value as 0. How to solve it?

Advertisement

Answer

double is perfectly capable of storing powers of two up to 1023 exactly. Don’t let someone tell you that floating point numbers are somehow always inexact. This is a special case where they aren’t!

JavaScript

Some output of the program:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement