大一c语言简单编程程序

img

求解答18题,刚接触c语言望有会的能够花您宝贵的几分钟时间指导一下,谢谢

因为fact()函数求阶乘函数是double类型,所以当n和m的数值过大时,结果不是很精确。
参考链接:
组合数计算器


#include <stdio.h>

//求阶乘 
double fact(int n){
    
    double result=1;
    int i;
    
    for(i=1;i<=n;i++){
        result*=i;
    }
    
//    printf("%d!=%lf\n",n,result);
    return result;
    
} 


int main(void){
    
    int m,n;
    printf("请输入两个正整数m和n(m<=n):");
    scanf("%d %d",&m,&n);
//    printf("m=%d,n=%d\n",m,n);
    
    //打印组合数, 当n和m的数值过大时,可能结果不会很精确
    printf("组合数是:%.0lf",(fact(n)/(fact(m)*fact(n-m))));
    
    return 0; 
    
}  

img