GMP and a quick addition example
Paul Leyland
paul at leyland.vispa.com
Mon Mar 10 16:29:11 CET 2008
This works for me. Compile with
gcc -o add_example add_example.c -lgmp -lm
#include <stdio.h> /* for printf */
#include <gmp.h>
int main(int argc, char *argv[])
{
mpz_t a, b; /* working numbers */
if (argc<3)
{ /* not enough words */
printf("Please supply two numbers to add.\n");
return 1;
}
mpz_init_set_str (a, argv[1], 10); /* Assume decimal integers */
mpz_init_set_str (b, argv[2], 10); /* Assume decimal integers */
mpz_add (a, a, b); /* a=a+b */
printf("%s + %s => %s\n", argv[1], argv[2], mpz_get_str (NULL, 10, a));
return 0;
}
YMMV.
Paul
On Mon, 2008-03-10 at 10:39, Daniel White wrote:
> Hello,
>
> I am interseted in using your arbitrary precision library.
>
> Just wondering - do you have a 'smallest possible program'
> example to say, add up two numbers like this page shows:
>
> http://www2.hursley.ibm.com/decimal/dnusers.html#example1
>
> Such examples are often good for people like me who are
> eager to learn quickly.
>
> Cheers, Daniel
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at swox.com
> https://gmplib.org/mailman/listinfo/gmp-discuss
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://gmplib.org/list-archives/gmp-discuss/attachments/20080310/2f9bec09/attachment.bin
More information about the gmp-discuss
mailing list