竞赛
考级
n = int(input()) def f(n): if n == 0: return 1 else: return n * f(n - 1) print(f(n))
#include <iostream> using namespace std; int f(int x) { if (x == 0) return 1; return x * f(x - 1); } int main() { int N; cin >> N; cout << f(N) << endl; return 0; }
#include<iostream> using namespace std; int f(int x){ if(x==0) return 1; return x*f(x-1); } int main(){ int n; cin>>n; cout<<f(n); return 0; } 其实这题并没有很复杂 注解:return 1这一步一定不能少不然会运行错误。PS:个人比较喜欢变量名都设成小写字母
提交答案之后,这里将显示提交结果~