Click here to Skip to main content
15,071,399 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If n is an integer, what is the next largest integer

What I have tried:

I dont know how to answer the question.
Posted
Updated 6-Sep-21 20:59pm
Comments
CPallini 7-Sep-21 2:36am
   
Uhm, (n+1) ?
:-D

1 solution

Have you considered
n + 1
as 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:
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900