武汉科技大学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,& ...
随机推荐
- Fedora 19+ 启动顺序调整
首先找到Windows 8的menuentry cat /boot/grub2/grub.cfg | grep Windows 设置Windows 作为默认的启动项 grub2-set-default ...
- sqlserver中Profiler的使用
1.单击开始--程序--Microsoft SQL Server 2008--性能工具--SQL Server Profiler,如下图: 2.然后进入SqlServ ...
- cypress的EZ-USB对于USB的介绍
Host is MasterThis is a fundamental USB concept. There is exactly onemaster in a USB system: the hos ...
- hibernate之CRUD操作
CRUD是指在做计算处理时的增加(Create).读取(Retrieve)(重新得到数据).更新(Update)和删除(Delete)几个单词的首字母简写. 下面列举实例来讲解这几个操作: 实体类: ...
- 值得IT运维人员警示的“一件事儿”
昨天,一个用户打来了紧急求助电话,并且发了邮件,弄得我当时紧张了一下,以为他们那里又出了什么乱子.用户在电话里说:应用系统性能很差,运行很慢,几近“卡死”的感觉,而且重启了多次应用和数据库服务器,最终 ...
- Linux下视频转换工具:转换,切割,连接,
首先当然是需要安装ffmpeg软件包,可以直接从源中进行安装!但我安装后并不能成功执行后面所需要执行的转换命令,所以我只能重新从源码编译安装ffmpeg: (1)下载ffmpeg源码包,注意版本不能太 ...
- POJ2524 Ubiquitous Religions(并查集)
题目链接. 分析: 给定 n 个点和 m 条无项边,求连通分量的数量.用并查集很简单. #include <iostream> #include <cstdio> #inclu ...
- (转载)PHP删除数组中的特定元素的代码
(转载)http://www.jb51.net/article/30689.htm 我们知道,PHP没有提供专门删除一个特定数组元素的方法.但是可以通过unset()函数来完成这种要求比如下面的程序: ...
- HDOJ 1048 The Hardest Problem Ever(加密解密类)
Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caes ...
- SKPhysicsContactDelegate协议
符合 NSObject 框架 /System/Library/Frameworks/SpriteKit.framework 可用性 可用于iOS .0或者更晚的版本 声明于 SKPhysicsWorl ...