赞
踩
已知求阶乘的函数如下,利用这个函数,编程计算并输出5*(1!+2!+...+n!)的值。注意函数Fact()返回的类型。
- unsigned long Fact(unsigned int n)
- {
- int i;
- unsigned long result = 1;
- for (i=2; i<=n; i++)
- result *= i;
- return result;
- }
输入整数n,n小于13。
sum=计算结果。
4
sum=165
- #include <stdio.h>
- int main()
- {
- unsigned long Fact(unsigned int n)
- {
- int i;
- unsigned long result = 1;
- for (i=2; i<=n; i++)
- result *= i;
- return result;
- }
- int a,b,sum;
- scanf("%d",&a);
- for (b=1;b<=a;b++)
- sum+=Fact(b);
- printf("sum=%u",sum*5);
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。