最终答案为零的方程组

Series of equation giving final answer as zero

我创建了这个旨在使用等式的程序
[F=(CP x CR x D)/(4 x pi x e x ((D^2+R^2)^3/2)]

哪里

CR = 戒指充电

CP = 充电点

R = 环的半径

D = 点到环的距离

e = 8.85 x 10^-12

F = 力

当我替换值时

2.00 x 10^-5 用于 CR (0.00002)

2.00 x 10^-05 CP (0.00002)

R 为 0.90

和 D

的 0.30

最终答案应该是F=1.263759

但我得到的是零。我对编程还很陌生,所以任何帮助将不胜感激

#include <stdio.h>
#include <math.h>

double calculatef(double, double, double, double, double, double);
double main()
{
    double CR; //Charge on Ring
    double CP; //Charge on point
    double R; //radius of Ring
    double D; //Distance between the point and ring
    double F; //Force

    int e = 8.85* pow(10,-12);
    printf("Please enter the values for the variables as follows:\n");
    printf("-Charge on the ring,\n -Charge on the point,\n -Radius of the ring\n");
    printf("-And the Distance between the center of the ring and the point:\n");

    scanf("%lf",&CR);
    printf("The charge on the ring is: %f\n", CR);

    scanf("%lf",&CP);
    printf("The charge on the point is: %f\n", CP);

    scanf("%lf",&R);
    printf("The radius of the ring is: %f\n", R);

    scanf("%lf",&D);
    printf("The distance between the center of the ring and the point is: %f\n", D);

    //The charge on the ring is 2e-005 Coulombs.
    //The charge on the point is 2e-005 Coulombs.
    //The radius of the ring is 0.90 m.
    //The distance between the center of the ring and the point is 0.30 m.
    //The force exerted on the point is 1.26 N.

    F == calculatef(CR,CP,R,D,e,F);

    printf("The force exerted on the point is %.2f\n", F);

    system("Pause");
}

double calculatef(double CR, double CP, double R, double D, double e, double F)
{
    e = 8.85* pow (10,-12);
    F=((D*D) * (R*R));
    F=(((CP * CR * D))/(pow(F,3/2)));
    F=(F/( 4 * 3.14 * e ));

    return(F);
}

问题似乎出在您对 e 的定义上。首先,您将一个非常小的浮点数分配给 int,有效地使其为零。其次,C有自己的科学记数法,所以你不用调用pow()。尝试将语句更改为:

double e = 8.85e-12;

除了关于e类型的回答还不错:

// int e = 8.85* pow(10,-12);
double e = 8.85* pow(10,-12);
// or simplify
double e = 8.85e-12;

代码在需要 FP 数学的地方使用整数数学。

// pow(F,3/2)
pow(F,3.0/2)

这些问题意味着 OP 没有启用所有编译器警告。节省时间 - 全部启用它们。