【发布时间】:2020-01-15 00:26:48
【问题描述】:
我是 C 编程的新手,遇到了一个小问题。
我输入 0.05 作为双浮点数,并通过我的解决方案图片中给出的公式运行它以获得答案 0.06242。但是,无论我输入什么作为输入,我都会得到 0.000000。有人可以向我解释我的代码是否有问题,或者解释我是否在 scanf 和 printf 中都正确使用了“%lf”?谢谢。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main(){
double guess, pow1,pow2,pow3, estimate;
printf("Type in an initial guess of the root(for this case type 0.05): ");
scanf("%lf", &guess);
printf("Calculating the root estimate using formula from solution...\n");
pow1 = pow(guess, 3);
pow2 = 0.165*pow(guess, 2);
pow3 = 3*pow(guess, 2);
estimate = guess - ((pow1 - pow2 + 0.0003993) / (pow3 - 0.33*guess));
printf("Estimate = %lf\n", estimate);
}
【问题讨论】:
-
逐行调试代码,看看值哪里出错了
-
什么是“双整数”?
-
不是双整数,是双浮点数
-
@DAGonz 这不是整数输入,而是浮点输入。你了解整数和浮点数的区别吗?
标签: c