Printing mpq_t in GMP library

414 views Asked by At

I've encountered a problem when trying to print mpq_t data type in GMP. Here is my code:

    #include <stdio.h>
    #include <stdlib.h>
    #include <gmp.h>

    int main(){
        mpq_t a;
        mpq_init(a);
        mpq_set_str(a, "41/152", 10);
        gmp_printf("the rational is: %Q\n",a);
        return 0;
    }

But it only prints out "the rational is: Q". I've followed the GMP manual(https://gmplib.org/manual/Formatted-Output-Strings.html), but couldn't find the bug. Help is much appreciated!

1

There are 1 answers

1
pts On BEST ANSWER

A d (stands for decimal) is missing after the Q:

gmp_printf("the rational is: %Qd\n",a);