C语言计算分段函数
/*革启博客,程序袁欢,袁欢的博客,袁欢博客
版本:vs2019社区版
功能:计算分段函数*/
#include<stdio.h>
double factorial(int a)
{
int i;
double factorial_Value = 1.0;
for (i = 1; i < a; 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);
}
欢迎指出代码的不足之处,我很高兴你能指出我的错误。
文档来源:51CTO技术博客https://blog.51cto.com/rjgx/3265297
页:
[1]