+ 1
In mathematics,the factorial of an integer n,denoted by n! is the following product:n!=1*2*...*n
For the given integer n calculate the value 1!+2!+3!+...+n! Try to discover the solution that uses only one for-loop.And don't use math module in this exercise. Ex input: 4 Ex output: 33 I can't do this!Could someone help me?
5 Respuestas
+ 4
周志桓
Sorry friend, this is not Python solution,
but you can use the algorithm!
// A simple for-loop calculation
int n = 10;
int result = 1;
for (int i = 1; i <= n; ++i) {
result *= i;
}
print( result ); //Output: 3628800
• We simply loop from 1 to n, adding the respectful number to the product at each iteration.
+ 1
Thanks Jay Matthews and Danijel lvanovic
0
You can use recursion
0
I use :for i in range...
But I don't know how to do it.
0
But it starts is:
a=int(input())
Ex input 5:
1!*2!*3!*4!*5!=153
Output is:
153