标签:i++ name 阶乘 clu 注意 logs 代码 turn log
此题不难,关键是20的阶乘是long long int 型的,这点需要注意!
AC不用递归的代码:
#include<iostream> using namespace std; int main() { int n; long long int res=1; while(cin>>n) { int i=1; res=1;; for (i=1;i<n+1;i++) res=res*i; cout<<res<<endl; } return 0; }
AC用递归的代码:
#include<iostream> using namespace std; long long int fact(int n); int main() { int n; while(cin>>n) { cout<<fact(n)<<endl; } return 0; } long long int fact(int n) { if (n==1)return 1; else return n*fact(n-1); }
题目1067:n的阶乘--------long long int
标签:i++ name 阶乘 clu 注意 logs 代码 turn log
原文地址:http://www.cnblogs.com/jianrenguo/p/6481082.html