实验5-2
/****從鍵盤輸入m和n,并計(jì)算m!/n!*(m-n)!****/
#include<stdio.h>
float fact(int n);???????? /*自定義函數(shù)的申明*/
int main(void)
{
???????? int? m,n;
???????? float a,b,c, y;
?
???????? printf("Enter m and n:");?????? /*輸入提示*/
???????? scanf("%d%d",&m,&n);
????????
?????????????????? a=fact(m);???????? /*調(diào)用自定函數(shù)fact(i)計(jì)算m的階乘*/
?????????????????? b=fact(n);
?????????????????? c=fact(n-m);
?????????????????? y=b/a*c;
???????? printf("%f",y);
return 0;
}
/*定義求n!的函數(shù)*/
float fact(int n)?????????? /*函數(shù)首部*/
{
???????? int i;
???????? float product;??????? /*單精度浮點(diǎn)型變量product用于存放結(jié)果(階乘的值)*/
???????? product=1;?????????? /*置階乘product的初始值為1*/
???????? for(i=1;i<=n;i++){??????????? /*循環(huán)n次計(jì)算n!*/
???????? product=product*i;
}
return product;???????????? /*將結(jié)果送給主函數(shù)*/
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/zhaoruiqi/p/3390818.html
總結(jié)
- 上一篇: Android视图组成View
- 下一篇: [译]GLUT教程 - 每秒帧数