2694 - 妈妈再也不用担心我不会做省赛题了
提起acm比赛,很多人都觉得难得要死,不想玩。其实不是这样的。
这个题是ACM协会2014年5月11日在威海参加山东省ACM/ICPC浪潮杯省级竞赛的原题,翻译后就是这么简单。
输入一个数,计算这个数的阶乘。请完成这个程序。
(PS:我校在这次比赛中获得了一枚银牌,三名队员(其中二人为大一新生)已经获得了保送中国石油大学研究生的资格)
Input
第一行是一个整数T(1<T<10)
以后T行,每行为一个整数N(1<N<=10)
Output
对每一行数据,在单独的一行中输出N的阶乘。
Examples
Input
2 3 2
Output
6 2
Solution C
#include<stdio.h> int main() { int n,a,i,s; s=1; scanf("%d",&n); while(n--) { scanf("%d",&a); for(i=1;i<=a;i++) { s=s*i; } printf("%d\n",s); s=1; } return 0; }
Solution C++
#include <iostream> #include <cstring> #include <fstream> using namespace std; int fact(int n) { int res=1; for(int i=n;i>=1;i--) { res*=i; } return res; } int main() { //ofstream cout; //ifstream cin; //cin.open("d.in"); //cout.open("d.out"); int testcase; cin>>testcase; while(testcase--) { int tmp; cin>>tmp; int res=fact(tmp); cout<<res<<endl; } return 0; }