problem with example of mpn_gcd
Blake Huff
stangmechanic at gmail.com
Sat Jul 29 20:55:37 CEST 2006
Wow that was a rude response. Not ALL of us are natural born
programmers, and most of us get in over our head at some point.
Anyways, here's some examples of how to call the gmp functions from
your code. Anyways, as Decio pointed out, these are rather
elementary C issues, so I suggest you brush up on your programming
before jumping into the GMP functions. There are certainly some
lists for C learners.
#include <stdio.h>
#include <gmp.h>
main (int argc, char **argv){
mpz_t a, b, p;
if (argc != 3)
{ printf ("Usage: %s <number> <number>\n", argv[0]); return
(1); }
/* Initialize and assign a and b from base 10 strings in argv */
mpz_init_set_str (a, argv[1], 10);
mpz_init_set_str (b, argv[2], 10);
/* Initialize p */
mpz_init (p);
/* compute the gcd of a and b*/
mpz_gcd(p, a, b);
// mp_size_t mpn_gcd (mp_limb_t *p, mp_limb_t *a,
// mp_size_an, mp_limb_t *b, mp_size_t bn)
/* Print p in base 10 */
gmp_printf("%Zd\n", p);
// mpz_out_str (stdout, 10, p);
// fputc ('\n', stdout);
/* Since we're about to exit, no need to clear out variables */
return (0);
}
On Jul 29, 2006, at 10:33 AM, Décio Luiz Gazzoni Filho wrote:
>> #include <stdio.h>
>> #include <gmp.h>
>>
>> main (int argc, char **argv)
>> {
>> mpz_t a, b, p;
>>
>> if (argc != 3)
>> { printf ("Usage: %s <number> <number>\n", argv[0]); exit
>> (1); }
>>
>> /* Initialize and assign a and b from base 10 strings in
>> argv */
>> mpz_init_set_str (a, argv[1], 10);
>> mpz_init_set_str (b, argv[2], 10);
>> /* Initialize p */
>> mpz_init (p);
>>
>>
>> /* compute the gcd of a and b*/
>> mp_size_t mpn_gcd (mp_limb_t *p, mp_limb_t *a,
>> mp_size_an, mp_limb_t *b, mp_size_t bn)
>>
>> /* Print p in base 10 */
>> mpz_out_str (stdout, 10, p);
>> fputc ('\n', stdout);
>>
>> /* Since we're about to exit, no need to clear out variables */
>> exit (0);
>> }
Blake Huff
stangmechanic at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20060729/f98031c9/attachment-0001.html
More information about the gmp-discuss
mailing list