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_uiright.Both of the above don’t work because it should actually be:
because this is how
gmp_printfrequires it.There’s a rather complete treatment of formatted output strings in GMP here.