Have some way to read a keyboard integer without digit boundary control. Type I need to pass a giant number via keyboard to a variable and then pass all the digits of that number to the ones in a list. Any suggestions?
Have some way to read a keyboard integer without digit boundary control. Type I need to pass a giant number via keyboard to a variable and then pass all the digits of that number to the ones in a list. Any suggestions?
You can use a buffer of chars
large enough to accommodate the integers as a string.
Large integer operations can be done using a GNU
library called gmplib .
Here is an example where the two arguments (large integers) passed to main()
are multiplied and their result displayed on the screen:
#include <gmp.h>
#include <stdio.h>
#define MAX_BUF_LEN (128)
int main( int argc, char * argv[] )
{
char res[ MAX_BUF_LEN ];
mpz_t a, b, c;
mpz_init(a);
mpz_init(b);
mpz_init(c);
mpz_set_str( a, argv[1], 10 );
mpz_set_str( b, argv[2], 10 );
mpz_mul( c, a, b );
mpz_get_str( res, 10, c );
printf("%s\n", res );
mpz_clear(a);
mpz_clear(b);
mpz_clear(c);
return 0;
}
compiling:
$ gcc -lgmp -Wall bigintmul.c -o bigintmul
Testing:
$ ./bigintmul 1234567890123456789012345678901234567890 9876543219876543219876543219876543210
Output:
12193263124676116335924401657049230176967230591384377380136092059011263526900
Checking: