n=int(input()) s,f=0,1 for i in range(1,n+1): f*=i s+=f print(s)
时间: 2024-05-19 10:12:30 浏览: 137
(C语言)输入n,统计0~n中1的个数。
5星 · 资源好评率100%
This code calculates the factorial of a given number 'n'.
Explanation:
- The user inputs a number 'n' using the 'input()' function.
- Two variables 's' and 'f' are initialized to 0 and 1 respectively.
- A 'for' loop is used to iterate from 1 to n-1.
- In each iteration, the value of 'i' is multiplied with 'f' and the result is stored in 'f'.
- Finally, the value of 'f' is assigned to 's'.
- The 'print()' function is used to display the value of 's' for each iteration.
Example:
If the user inputs 5, the output will be:
1
2
6
24
阅读全文