C语言计算分段函数

2021-04-10 20:28

阅读:1171

标签:double   factorial   bsp   clu   版本   功能   class   参数   pre   

/*
革启博客,程序袁欢,袁欢的博客,袁欢博客
版本:vs2019社区版
功能:计算分段函数*/
#includedouble factorial(int a)
{
    int i;
    double factorial_Value = 1.0;
    for (i = 1; i )
    {
        factorial_Value = factorial_Value * i;
    }
    return factorial_Value;
}
void main()
{
    int m = 0, n = 0;
    double factorial_m = 0;
    double factorial_n = 0;
    double factorial_mn = 0;
    double P_mn = 0.0;
    printf("请输入两个参数的值:\n");
    printf("m=");
    scanf_s("%d", &m);
    printf("n=");
    scanf_s("%d", &n);
    if (m > n)
    {
        factorial_m = factorial(m);
        factorial_n = factorial(n);
        factorial_mn = factorial(m - n);
        if (0 == factorial_n || 0 == factorial_mn)
        {
            printf("错误,0不能作为除数!\n");
        }
        else
        {
            P_mn = factorial_m / (factorial_n * factorial_mn);
        }
    }
    else
    {
        P_mn = 0;
    }
    printf("计算结果为:");
    printf("P_mn=%f\n", P_mn);
}

 

C语言计算分段函数

标签:double   factorial   bsp   clu   版本   功能   class   参数   pre   

原文地址:https://www.cnblogs.com/qq1480040000/p/13365660.html


评论


亲,登录后才可以留言!