1131: 零起点学算法38——求阶乘和
生活随笔
收集整理的这篇文章主要介绍了
1131: 零起点学算法38——求阶乘和
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1131: 零起点学算法38——求阶乘和
Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 2719 Accepted: 1736
[Submit][Status][Web Board]
Description
输入一个正整数n(n<=10),计算
S=1!+2!+3!+...+n!
Input
输入一个正整数n(n<=10)(多组数据)
Output
输出S(每组数据一行)
Sample Input
2
Sample Output
3
Source
零起点学算法
1 #include<stdio.h> 2 int main(){ 3 int n; 4 while(scanf("%d",&n)!=EOF){ 5 long long s=0; 6 for(int i=1;i<=n;i++){ 7 long long sum=1; 8 for(int j=i;j>0;j--){ 9 sum*=j; 10 } 11 s+=sum; 12 } 13 printf("%lld\n",s); 14 } 15 return 0; 16 }
转载于:https://www.cnblogs.com/dddddd/p/6680406.html
《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读总结
以上是生活随笔为你收集整理的1131: 零起点学算法38——求阶乘和的全部内容,希望文章能够帮你解决所遇到的问题。