Prolem with Integer Division
jack THE RED
jack_the_red at hotmail.fr
Sat Feb 6 15:29:28 CET 2010
Hi everyone!
I'm new to GMP and I have a problem regarding the integer division.
I did read the manual and tried a lot of the division function.
But the result is always something weird:
"so 1234 = 2 x 3218735876"
Can someone tell me what is the problem?
Code:
#include <stdio.h>
#include <gmp.h>
int main(){
mpz_t n;
mpz_t root;
mpz_t remainder;
mpz_t s;
mpz_init (n);
mpz_init (root);
mpz_init (remainder);
mpz_init (s);
printf("Please enter a number to by two: \n");
gmp_scanf ("%Zd",&n);
gmp_printf("number inputed %Zd \n", n);
mpz_sqrt(root,n);
gmp_printf("number root %Zd \n", root);
mpz_set(s,n);
mpz_mod_ui(remainder,s,2);//remainder <- n%2
if (mpz_cmp_ui(remainder,1)){// if remainder!=1 (means that n is an even number)
gmp_printf("This is an even number, so %Zd = 2 x ", n);
mpz_div_ui(n, n, 2); /// Error here!
gmp_printf("%lu \n", n);
}
mpz_clear (n);
mpz_clear (root);
mpz_clear (remainder);
mpz_clear (s);
return 0;
}
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969
More information about the gmp-discuss
mailing list