Thread: mpz_mul(r, b, x);

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    130

    mpz_mul(r, b, x);

    Hi all,

    I have this code:

    Code:
    #include        <stdio.h>
    #include        <gmp.h>
    
    
    int main (int argc, char* argv[])
    {
            printf("Here!");
            mpz_t   b, x, r;
    
    
            if (argc != 2) {
                    printf("Help");
                    return 2;
            }
    
            mpz_init(b);
            mpz_init(x);
            mpz_init(r);
    
            gmp_sscanf(argv[1], "%Zd", b);
            gmp_sscanf(argv[2], "%Zd", x);
    
            printf("X = %Zd Y = %Zd",b,x);
            mpz_mul(r, b, x);
    
            gmp_printf("%Zd * %Zd = \n", b, x, r);
            printf("Entered");
    
            return 0;
    }
    The mutliplication is not working. Actually, it prints only the first print
    statement : Here!.

    Any suggestions?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > printf("X = &#37;Zd Y = %Zd",b,x);
    Why isn't this
    gmp_printf("X = %Zd Y = %Zd",b,x);

    Did you run the program with two command line arguments?
    argc would be 3 by the way.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    130
    Quote Originally Posted by Salem View Post
    > printf("X = &#37;Zd Y = %Zd",b,x);
    Why isn't this
    gmp_printf("X = %Zd Y = %Zd",b,x);

    Did you run the program with two command line arguments?
    argc would be 3 by the way.
    Yeah, I run it with 2 args:

    $ ./mul.exe 2 3

    As I changed the printf() to gmp_printf(), but with no changes

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    130
    Oh, I got where is the mistake.
    Thanks Salem.

Popular pages Recent additions subscribe to a feed