I've just started messing with GMP and I can't seem to get numbers to print properly. Here is what I'm trying:
#include <stdio.h>
#include <stdlib.h>
#include "gmp.h"
int main(){
mpz_t n;
mpz_init (n);
mpz_set_ui(n, 2);
gmp_printf("attempt 1: %d \n", n);
gmp_printf("attempt 2: %Z \n", n);
return 0;
}
I know this must be something really simple... but I'm just not seeing it.
My output is:
attempt 1: 1606416528
attempt 2: Z
I think I might just be using mpz_set_ui wrong...
EDIT:
%Zd works I also tried %n which I thought would work, but doesn't... definitely need some help on this.
You are using mpz_set_ui
right.
gmp_printf("attempt 1: %d \n", n);
gmp_printf("attempt 2: %Z \n", n);
Both of the above don't work because it should actually be:
gmp_printf("attempt 3: %Zd \n", n);
because this is how gmp_printf
requires it.
There's a rather complete treatment of formatted output strings in GMP here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With