problem with example of mpn_gcd
Alan McFarlane
alan.mcfarlane at gmail.com
Sat Jul 29 20:22:57 CEST 2006
Try this code Jang...
#include <stdio.h>
#include <stdlib.h> /* needed for exit() prototype */
#include <gmp.h>
int 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*/
mpz_gcd(p, a, b);
/* 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 */
/* But, we will do (force of habit!) */
mpz_clear(p);
mpz_clear(b);
mpz_clear(a);
exit (0);
}
As for Décio's comments, they make me ashamed to be a programmer.
Everyone has to learn somewhere, and I'll bet we all make simple
mistakes (at least to those with a bit more experience).
Be nice Décio :)
--
Alan McFarlane
Décio Luiz Gazzoni Filho wrote:
>
> On Jul 29, 2006, at 1:50 AM, Jiang wf wrote:
>
>> hello, everyone,
>>
>> I just want use mpn_gcd to make a program, that can calculate gcd of
>> two big integers, the following is my code named agcd.c:
>>
>>
>>
>> #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);
>> }
>>
>>
>>
>> and when compiled, got the following error:
>>
>> agcd.c: In function 'main':
>> agcd.c:9: warning: incompatible implicit declaration of built-in
>> function 'exit'
>> agcd.c:20: error: syntax error before 'mp_size_an'
>>
>>
>>
>>
>> so, please, anyone can give me some advise about this problem, thanks!
>
> Well I can. Drop any pretenses of being a computer programmer and go be
> a manager or CEO somewhere. You don't have what it takes to be a
> programmer.
>
> And whether you follow my advice or not, do not post to this mailing
> list anymore. Your email nearly made me sick to my stomach.
>
> Décio
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at swox.com
> https://gmplib.org/mailman/listinfo/gmp-discuss
More information about the gmp-discuss
mailing list