C:我的';泊松计算器&x27;给我1.00英镑。为什么会发生这种情况?

C:我的';泊松计算器&x27;给我1.00英镑。为什么会发生这种情况?,c,floating-point,poisson,C,Floating Point,Poisson,在此之前,我的代码是: #include <stdio.h> #include <conio.h> #include <math.h> main() { float Exp, Act, Px, Facto_Act; printf("\n This is Poisson Distribution Calculator!"); printf("\n Enter the expected value of success in a time

在此之前,我的代码是:

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

main()
{
    float Exp, Act, Px, Facto_Act;
    printf("\n This is Poisson Distribution Calculator!");
    printf("\n Enter the expected value of success in a time period:");
    scanf("%f",& Exp);
    printf("\n Enter the actual or calculated value of success in a time period:");
    scanf("%f",& Act);
    Px=pow(M_E,-Exp)*pow(Exp,Act)/Facto_Act;
    printf("\n Poisson probability is:%f", Px);
    getch();
    return 0;
}

Facto_Act(float Act)
{
    float c;
    float result=1;
    for(c=1;c<=Act;c++)
        result=result*c;
    return result;
}
#包括
#包括
#包括
main()
{
浮点数Exp、Act、Px、Act;
printf(“\n这是泊松分布计算器!”);
printf(“\n输入一段时间内成功的预期值:”);
scanf(“%f”、&Exp);
printf(“\n输入一段时间内成功的实际值或计算值:”;
scanf(“%f”、&Act);
Px=pow(me,-Exp)*pow(Exp,Act)/事实行为;
printf(“\n泊松概率为:%f”,Px);
getch();
返回0;
}
事实法(浮动法)
{
浮点数c;
浮动结果=1;

对于(c=1;c您声明了一个名为FactoAct的float类型变量。由于它是一个没有初始化的外部变量,因此它的值为0

稍后,您将定义一个隐式返回类型为“int”的函数factor_Act(float Act)

除法xxx/FactoAct将xxx除以变量FactoAct,即零。这就是INF结果的来源

当你把函数放在顶端时,当编译器看到xxx/FactoAct时,FactoAct不是调用函数的结果,而是函数本身。你不能用一个函数除以一个数字。这是没有意义的。你能做的唯一一件事就是获取它的地址,或者调用它

你可能想要FactoAct(x)或类似的东西


注:不要使用float而不是double,除非你有一个理由可以清楚地解释为什么在你的特定情况下float比double好。

Px=pow(me,-Exp)*pow(Exp,Act)/fact_Act;
…请不要告诉我这个编译很好。“当我知道如何在C中对整数进行阶乘时,我将尝试为正小数添加阶乘"小数的阶乘?它们是如何在数学上定义的?我认为你误解了泊松事件。它们必须是一个整数。例如,你可以尝试预测给定时间范围内给定道路上的车祸数量。你可以有0、1、2或更多;你不能有0.7或2.345次车祸。它们必须是整数。平均值可以是十进制,但事件数必须是整数。Sourav Ghosh,实际上不是。我在编译时出错,说事实不能被除。如果我没记错的话,float/double(double).但是,将事实行为重新排列到底会以某种方式消除所宣布的错误。法比奥·图拉蒂,我认为我错了。我不太擅长统计。但我确实提出了一些问题,一个小时内出现2.4次故障,或者一天4.2次电话呼叫,但是的,这样的事件应该是离散的。我提到的网页:我决定逃避函数pro但如果下次我想调用一个函数作为分子,我该怎么做呢?
#include <stdio.h>
#include <conio.h>
#include <math.h>


main()
{
    double Exp, Px;
    int c, Act, Act2, Facto_Act=1;
    printf("\n This is Poisson Distribution Calculator!");
    printf("\n Enter the expected value of success in a time period:");
    scanf("%lf",& Exp);
    printf("\n Enter the actual or calculated value of success 
    \n in a time period(must be an integer!):");
    scanf("%d",& Act);
    /*My factorial starts here*/
    for (c=1;c<=Act;c++)
        Facto_Act=Facto_Act*c;
    /*My factorial ends here*/
    Px=(pow(M_E,-Exp))*(pow(Exp,Act))/Facto_Act;
    printf("\n Poisson probability is:%lf", Px);
    getch();
    return 0;
}