gpt4 book ai didi

c - GMP gmp_printf()

转载 作者:太空狗 更新时间:2023-10-29 15:20:19 26 4
gpt4 key购买 nike

我刚开始弄乱 GMP,我似乎无法正确打印数字。这是我正在尝试的:

#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;
}

我知道这一定很简单......但我就是没看到。

我的输出是:

attempt 1: 1606416528 
attempt 2: Z

我想我可能只是错误地使用了 mpz_set_ui...

编辑:

%Zd 有效我也尝试了 %n,我认为它有效,但没有...在这方面绝对需要一些帮助。

最佳答案

正在正确使用mpz_set_ui

gmp_printf("attempt 1: %d \n", n);
gmp_printf("attempt 2: %Z \n", n);

以上两个都不起作用,因为它应该实际上是:

gmp_printf("attempt 3: %Zd \n", n);

因为这是 gmp_printf 的要求。

GMP 中对格式化输出字符串的处理相当完整 here .

关于c - GMP gmp_printf(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11630096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com