2013年10月21日

实验5-1计算1!+2!+…+100!。要求定义和调用函数fact(n)计算n的阶乘

摘要: /*计算1!+2!+…+100!。要求定义和调用函数fact(n)计算n的阶乘*/#includedouble fact(int n);int main(void){ int i; double sum; sum=0; for(i=1;i<=100;i++) sum=sum+fact(i); /*阶乘相加*/ printf("1!+2!+……+100!=%e\n",sum); return 0;}double fact(int n) /*计算n的阶乘*/{ int i; double result; result=1;... 阅读全文

posted @ 2013-10-21 09:23 chcb111 阅读(3954) 评论(0) 推荐(0) 编辑

实验5-2: 编制程序,输入m、n(m≥n≥0)后,计算下列表达式的值并输出。 要求将计算阶乘的运算编写作函数fact(n),函数返回值的类型为float

摘要: /*编制程序,输入m、n(m≥n≥0)后,计算下列表达式的值并输出。 要求将计算阶乘的运算编写作函数fact(n),函数返回值的类型为float*/#includedouble fact(int j);int main(void){ int m,n; double s; printf("enter m:"); scanf("%d",&m); printf("enter n:"); scanf("%d",&n); s=fact(m)/(fact(n)*fact(m-n)); printf(" 阅读全文

posted @ 2013-10-21 09:21 chcb111 阅读(1733) 评论(0) 推荐(0) 编辑

导航