Home > other >  How can I set value of a variable to an amount that is more than unsigned long long maximum value in
How can I set value of a variable to an amount that is more than unsigned long long maximum value in

Time:08-07

I know that The maximum value for a variable of type unsigned long long in C is:

18,446,744,073,709,551,615

but I don't know that how can I set value of a variable to an amount that is more than 18,446,744,073,709,551,615?

CodePudding user response:

In vanilla C you can't, however, you can use Boost's multi-precision library.

CodePudding user response:

maybe you can use __int128,the only problem is that you can't use cin,cout or printf but you can write a function like that:

//output
inline void write(__int128 x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x '0');
}
//input
inline __int128 read()
{
    __int128 X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3) (X<<1) (ch^48),ch=getchar();
    return w?-X:X;
}
  •  Tags:  
  • c
  • Related