0

I am trying to do modulus operator on number upto 10^18. i cannot store this numbers in int and if i take it float then i cannot apply modulus operator so how can i do it.

I searched it but didn't find my answer.

I found one method to typecast but it cannot solve my problem and other is to use array.

So , there is only way to use array.

  • 1
    You don't show the calculation, but it can be posssible to do the modulus on its steps, so it never gets large. – Weather Vane Feb 11 '16 at 19:59
  • 4
    If you're using the C99 standard or later, you can use the [long long](https://en.wikipedia.org/wiki/C_data_types#Basic_types) type, which is at least 64 bits, and will hold 10^18. – skrrgwasme Feb 11 '16 at 20:00
  • Possible duplicate of [Declaring 64-bit variables in C](http://stackoverflow.com/questions/19451101/declaring-64-bit-variables-in-c) – user3386109 Feb 11 '16 at 20:02
  • Here is a list from wikipedia: https://en.wikipedia.org/wiki/List_of_C%2B%2B_multiple_precision_arithmetic_libraries but it doesn't include all of them - there are a bunch more. See: https://www.google.co.nz/search?q=c%2B%2B+arbitrary+precision – Jerry Jeremiah Feb 11 '16 at 20:17
  • You have kind of modulus operations on floating point see for example http://linux.die.net/man/3/remainder - it's just that 10^18 takes about 60 bits of data, a bit too much for IEEE double precision – aka.nice Feb 11 '16 at 21:08

2 Answers2

3

Use a long long int which ranges from −9,223,372,036,854,775,808 to +9,223,372,036,854,775,807. For unsigned values you can use unsigned long long int, which ranges from 0 to 18,446,744,073,709,551,615

Here are your choices

long long
long long int
signed long long
signed long long int
unsigned long long
unsigned long long int
user3386109
  • 34,287
  • 7
  • 49
  • 68
Jonh Doe
  • 761
  • 1
  • 9
  • 25
  • yeah it's more like it depends on the platform, and the edited version by user3386109 is correct. – Jonh Doe Feb 11 '16 at 20:15
  • the int is optional so long long is equal to long long int, but I suggest using long long int it's clearer for non C or new C programmers. – Jonh Doe Feb 11 '16 at 20:27
0

For long number you can use unsigned long long int or long long int If this not working for you than you can use filing for storing values.

Faraz Sultan
  • 203
  • 2
  • 13