等式系列给出最终答案为零

时间:2017-09-30 14:24:37

标签: c codeblocks

我创建了这个程序,用于使用公式
[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)

0.90对于R

和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);
}

2 个答案:

答案 0 :(得分:0)

问题似乎与您对double e = 8.85e-12; 的定义有关。首先,您要为{{1}}分配一个非常小的浮点数,实际上将其设为零。其次,C有自己的科学记法形式,所以你不必打电话给{{1}}。尝试将语句更改为:

{{1}}

答案 1 :(得分:0)

除了@luther关于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未启用所有编译器警告。节省时间 - 全部启用。