武汉科技大学ACM :1002: 零起点学算法38——求阶乘和
Problem Description
输入一个正整数n(n<=10),计算
S=1!+2!+3!+...+n!
Input
输入一个正整数n(n<=10)(多组数据)
Output
输出S(每组数据一行)
Sample Input
2
Sample Output
3
#include<stdio.h>
int main()
{
long int s,a;
int i,n;
while(scanf("%d",&n)!=EOF)
{
s=;
a=;
for(i=;i<=n;i++)
{
a=a*i;
s=s+a;
}
printf("%ld\n",s);
}
return ;
}
其他代码:
#include<stdio.h>
int ridsum(int n)
{
int sum,i;
if(n==||n==)
return ;
else
return ridsum(n-)*n;
}
int main()
{
int n,sum,i;
while(scanf("%d",&n)!=EOF)
{
for(i=,sum=;i<=n;i++)
sum+=ridsum(i);
printf("%d\n",sum);
}
return ;
}
武汉科技大学ACM :1002: 零起点学算法38——求阶乘和的更多相关文章
- 武汉科技大学ACM :1002: 零起点学算法66——反话连篇
Problem Description 把输入的字符按照反着顺序输出 Input 多组测试数据 每组一行(每组数据不超过200个字符) Output 按照输入的顺序反着输出各个字符 Sample I ...
- 武汉科技大学ACM :1002: 零起点学算法28——判断是否闰年
Problem Description 输入年份,判断是否闰年 Input 输入一个整数n(多组数据) Output 如果是闰年,输出yes,否则输出no(每组数据一行) Sample Input 2 ...
- 武汉科技大学ACM :1010: 零起点学算法12——求2个日期之间的天数
Problem Description 水题 Input 输入2个日期,日期按照年月日,年月日之间用符号-隔开(题目包含多组数据) Output 求出这2个日期之间的天数(不包括自身),每组测试数据一 ...
- 武汉科技大学ACM :1006: 零起点学算法25——求两点之间的距离
Problem Description 输入平面坐标系中2点的坐标,输出它们之间的距离 Input 输入4个浮点数x1 y1 x2 y2,分别是点(x1,y1) (x2,y2)的坐标(多组数据) Ou ...
- Problem Z: 零起点学算法22——求正弦和余弦
#include<stdio.h> #include <math.h> int main() { int n; ); double a,b; while(scanf(" ...
- Problem W: 零起点学算法21——求平均值
#include<stdio.h> int main() { int a,b,c; scanf("%d %d %d",&a,&b,&c); pr ...
- Problem R: 零起点学算法13——求2个时间之间的分钟数
#include<stdio.h> int main() { int a1,b1,a2,b2,s; scanf("%d:%d",&a1,&b1); sc ...
- Problem Q: 零起点学算法12——求2个日期之间的天数
#include<stdio.h> int main() { int a1,b1,c1,a2,b2,c2,s; scanf("%d-%d-%d",&a1,&am ...
- Problem O: 零起点学算法10——求圆柱体的表面积
#include<stdio.h> int main() { float r,h,pi; pi=3.1415926; scanf("%f %f",&r,& ...
随机推荐
- 转:nginx防DDOS攻击的简单配置
文章来自于: 近期由于工作需要,做了些防DDOS攻击的研究,发现nginx本身就有这方面的模块ngx_http_limit_req_module和ngx_http_limit_conn_module. ...
- out.print和out.write方法
<%@ page language="java" import="java.util.*" %> <%@ page pageEncoding= ...
- Chapter 7 Backup and Recovery 备份和恢复:
Chapter 7 Backup and Recovery 备份和恢复: Table of Contents 7.1 Backup and Recovery Types 7.2 Database Ba ...
- BZOJ2274: [Usaco2011 Feb]Generic Cow Protests
2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 196 Solve ...
- 将多个图片整合到一张图片中再用CSS 进行网页背景定位
原文地址:http://wenku.baidu.com/link?url=hj_qM9kmdMrg8KWXFD2bCF_uuJCxKJRvG97CkWk3itsPq3izMzfrKvSZYBzDGyP ...
- 微软 Microsoft
微软(Microsoft Corporation) (NASDAQ:MSFT,港交所:4338),是一家基于美国的跨国电脑科技公司,是世界PC(Personal Computer,个人计算机)机软件开 ...
- ssh远程连接不上ubuntu
问题描述: 1.ubuntu安装了openssh-server,启动了ssh 守护进程,使用端口22 2.在本机可以 ssh 127.0.0.1 连接 3.通过ssh远程(比如用putty 或crt) ...
- Media层
媒体层包含图形技术.音频技术和视频技术,这些技术相互结合就可为移动设备带来最好的多媒体体验,更重要的是,它们让创建外观音效俱佳的应用程序变得更加容易.您可以使用iOS的高级框架更快速地创建高级的图形和 ...
- Reachability下载地址
https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html
- mysql 数据库连接(远程和本地原理同样)
mysql 连接远程数据库的时候的格式 mysql -uuser -hhost -Pport -ppassword