zoukankan      html  css  js  c++  java
  • 实验4-2 关于求阶乘的运算

    /*计算阶乘的运算编写作函数fact(n)*/
    #include<stdio.h>
    double fact(int n);/*函数声明*/
    int main(void)
    {
        int n,m;
        double result,denominator,molecule;/*denominator为函数,molecule为函数的分子*/
        printf("Enter n:");/*输入提示*/
        scanf("%d",&n);
        printf("Enter m:");/*输入提示*/
        scanf("%d",&m);
        if(m<n){/*判断输入是否正确*/
            printf("Enter is wrong");
        }
        molecule=fact(m);/*调用自定义函数fact(i)计算i!*/
        denominator=fact(n)*(fact(m-n));/*调用自定义函数fact(i)计算i!*/
        result=molecule/denominator;
        printf("result=%.2f
    ",result);
        return 0;
    }
    /*定义求n!的函数*/
    double fact(int n)/*函数部首*/
    {
        int i;
        double product;/*product用于存放阶乘的值*/
        product=1;
        for(i=1;i<=n;i++){
             product=product*i;
        }
        return product;/*将结果会送到函数*/
    }

     
  • 相关阅读:
    mybatis mapper配置
    python 练习题
    python 函数
    python 文件处理
    python3 编码解码
    messagebox
    Python 基础
    PyMongo
    tkinter Text
    python tkinter entry
  • 原文地址:https://www.cnblogs.com/shenyunwen/p/3380028.html
Copyright © 2011-2022 走看看