码迷,mamicode.com
首页 > 编程语言 > 详细

1131: 零起点学算法38——求阶乘和

时间:2017-04-08 01:00:05      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:problems   分享   arc   inpu   ret   style   can   image   ext   

1131: 零起点学算法38——求阶乘和

Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld
Submitted: 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 }

 

1131: 零起点学算法38——求阶乘和

标签:problems   分享   arc   inpu   ret   style   can   image   ext   

原文地址:http://www.cnblogs.com/dddddd/p/6680406.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!