I am trying to solve a code which requires me to input and output integer value upto 18 digits. Unfortunately i am unable to store the value in any data type. I have already tried
long int
unsigned long long
long long double,
None of these seem to work.Can u Please suggest me something that might help me output the value.
www.geeksforgeeks.org/advanced-c-boost-library/amp/ There is a rule by which you can calculate how many digit a data type can store and the logic is 2^10 = 10^3 (nearly) i.e as long long int is an 64 bit integer, it can support 18 digit number because 2^64 = 10^18(nearly) by the above rule.
The long long data type is overkill for just about every application, but C will let you use it anyway. It's capable of storing at least −9,223,372,036,854,775,807 to 9,223,372,036,854,775,807. Alternatively, get even more overkill with unsigned long long , which will give you at least 0 to 18,446,744,073,709,551,615.
The INTEGER data type stores whole numbers that range from -2,147,483,647 to 2,147,483,647 for 9 or 10 digits of precision. The number 2,147,483,648 is a reserved value and cannot be used. The INTEGER value is stored as a signed binary integer and is typically used to store counts, quantities, and so on.
Unsigned long long can only store around 18 digits.
Data types in C decide what can be stored in a variable, and memory is allocated accordingly. For example, a variable can store a simple numeric digit in an int type variable, a letter of the alphabet in a char type variable, or a decimal number in a float type variable.
Originally Answered: Which data type should I use to store a 12 digit integer in C++? Rule of thumb: you need 3 and a half bits (well, slightly less actually) to store a digit. Henceforth, for 12 digits 32 bits are not enough, but 64 bits are.
The int data type can store whole numbers from -2147483648 to 2147483647. In general, and in our tutorial, the int data type is the preferred data type when we create variables with a numeric value.
char: The most basic data type in C. It stores a single character and requires a single byte of memory in almost all compilers. int: As the name suggests, an int variable is used to store an integer.
18 digits gives a maximum possible value of 999,999,999,999,999,999 ≈ 9.9 × 1017. This will fit into an unsigned, 64-bit integer (maximum value 264, which is about 1.8446744 × 1019). Try using the uint64_t
type to ensure that you get this.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With