How to receive a number X ranging from 0 to 10 ^ 100 in C?

4

I have a question that can have as input an X number that can be from 0 to 10 ^ 100. I am getting the values / entry number as char to facilitate. But you can not create a static string / vector of char that behaves this way. How to proceed?

    
asked by anonymous 31.03.2015 / 17:27

2 answers

1

You can use a stack or a dynamic string to behave (with malloc ). Depending on the case, it's worth it to use a large number library ready than creating one yourself.

    
10.04.2015 / 22:09
1

How about stocking the number progressively in a double?

#include <math.h> //pow()
int c;
long double valor = 0.0;
double potencia_de_dez = 0;
while ( (c = getchar()) != EOF )
{
    //Incrementa valor com o numero de entrada 
    valor += double(c - '0') * pow(10.0, potencia_de_dez);
    ++potencia_de_dez;
}
    
19.04.2015 / 11:34