Copy Code

n + 1as a solution?

It really depends on what you are doing: if you are talking number theory, then "n + 1" is right, but in computing it's not that simple because it depends on the data type - since they use a fixed amount of memory, they have a limit on the "largest value" they can store.

For an 8 bit number, the largest positive value is either 255 or 127, depending on whether the variable storing it is unsigned or signed - in the later case, "127 + 1" will either be -128 or -0 (depending on the system your code runs on). For unsigned byte values 255 + 1 is 0.

For 16 bit integers the limits are different: 32767, and 65535.

For floating point numbers it's even worse, because the precision with which they are stored may mean that n + 1 is the same as n ... :laugh:

:-D