I am doing a basic program that does calculations with very large numbers, what I do is read it as String
and the idea is that I multiply each digit of the number by a large number (for example 100000
).
#include <stdio.h>
#include <string.h>
#include <math.h>
int main( ) {
char cadena[1000];
char cadena2[1000];
scanf( "%s", cadena2 );
for( unsigned i = 0; i < strlen( cadena2 ); ++i ) {
cadena[i] = cadena2[i] - '0';
cadena[i] *= 100000;
cadena[i] = cadena[i] + '0';
}
printf( "%s", cadena);
return 0;
}
but logically it overflows and at the time of printing, that is, what is expected does not come out.
My question is how can I save a number so large that it should only be read as String
?
Thank you!
PS: I had already asked a question associated with this topic . Operation with a numeric value of a digit does not produce the expected result.