Begineer关于伯爵的问题 [英] Begineer's question about count
本文介绍了Begineer关于伯爵的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
参考书显示答案是
The reference book shows the answer is
h(g) = 3.1415e-005
count = 18
但我的答案是
but my answer is
h(g) = 3.1415e-005count = 0
#include <stdio.h>
int main()
{
int count, a = 2046;
short b = 234;
long c = 5555;
unsigned int d = 1234;
char e = 'z';
float f = 3.14159f;
double g = 3.1415926535898;
double h = 3.1415e-5;
printf("a(d) = %d\n", a);
printf("a(o) = %o\n", a);
printf("a(x) = %x\n", a);
printf("b(d) = %d c(d) = %d\n", b, c);
printf("d(u) = %u\n", d);
printf("e(c) = %c\n", e);
printf("f(f) = %f\n", f);
printf("g(f) = %f\n", g);
printf("g(e) = %e\n", g);
printf("g(g) = %g\n", g);
printf("h(f) = %f\n", h);
printf("h(e) = %e\n", h);
printf("12345678901234567890\n");
printf("h(g) = %g%n\n", h, &count);
printf("count = %d\n", count);
printf("b(d) = %d f(f) = %f\n", b, f);
return 0;
}
我的尝试:
删除%n和&在
What I have tried:
remove %n and & in
printf("h(g) = %g%n\n", h, &count);
推荐答案
你没有指定一个值来计算,所以它仍然是偶然初始化的零值。
Nowhere do you assign a value to count, so it remains at the fortuitously initialised vaue of zero.
程序
The program
#include <stdio.h>
int main()
{
double h = 3.1415e-5;
int count;
printf("h(g) = %g%n\n", h, &count);
printf("count = %d\n", count);
return 0;
}
产出
Outputs
h(g) = 3.1415e-05
count = 17
在我的 Linux
框中( gcc 5.4.0
)。
这篇关于Begineer关于伯爵的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文