小编DAG*_*onz的帖子

我在方程式中输入一个双整数,但一直保持为0

我对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);
}
Run Code Online (Sandbox Code Playgroud)

c

3
推荐指数
1
解决办法
89
查看次数

标签 统计

c ×1