实验5(2)

#include<stdio.h>
int main()
{
    int m,n;
    float result,sum;
    float fact(int n);
    printf("enter m and n:");/*显示输入m和n*/
    scanf("%d%d",&m,&n);/从键盘输入m和n*/
    sum=fact(m-n);/*定义sum*/
    result=fact(m)/(fact(n)*sum);/*定义result*/
    printf("result=%.0f\n",result);
    return 0;
}
float fact(int n)
{
    int i;
    float result;
    result=1;
    for(i=1;i<=n;i++){/*设置循环,当i<=n时循环,且每完成一次循环,i+1*/
        result=result*i;
    }
    return result;
}

posted @ 2013-10-30 23:28  跃映峰影  阅读(118)  评论(0编辑  收藏  举报