4 条题解

  • 2
    @ 2026-5-30 10:27:02

    #include using namespace std;

    int main() { int a, b = 1; cin >> a; for (int i = 1; i <= a; i++) { b = b * i; } cout << b; return 0; }

    • 1
      @ 2026-8-27 16:43:05

      A1004【入门】编程求123*...*n 题解

      题目传送门

      题目传送门(内网)

      此处食用更佳

      提供一种递归写法

      求 1*2*3*……*n 其实就是求 n 的阶乘

      求 n 的阶乘的方法如下:

      n!=n(n1)!n! = n*(n-1)!

      即 n的阶乘 = n* (n-1)的阶乘

      递归时,每一层返回当前层的 x求阶乘(x-1)

      AC code:

      #include <bits/stdc++.h>//万能头文件
      using namespace std;//std命名空间
      int n;
      
      int jiecheng(int x){//求阶乘
      	if(x==1||x==0) return 1;//如果x=0或x=1,返回1,1和0的阶乘是1
      	return x*jiecheng(x-1);//返回x * 求阶乘(x-1)
      }
      
      
      int main() {
      
      	cin>>n;//输入
      
      	cout<<jiecheng(n);//输出n的阶乘
      	return 0;
      }
      
      

      AC记录

      AC记录(内网)

      • 1
        @ 2026-5-31 8:44:55

        #include <bits/stdc++.h> using namespace std;

        int main() { int a, num = 1; cin >> a; for (int i = 1; i <= a; i++) { num = num * i; } cout << num; return 0; }

        • 0
          @ 2026-5-30 17:26:45

          #include <bits/stdc++.h> using namespace std;

          int main() { int a, b = 1; cin >> a; for (int i = 1; i <= a; i++) { b = b * i; } cout << b; return 0; }

          • 1

          信息

          ID
          30050
          时间
          1000ms
          内存
          256MiB
          难度
          1
          标签
          递交数
          74
          已通过
          59
          上传者