Write a program to print the factorial of a number input by the user.
Answers
Answered by
3
Answer:
Here you go,
_____________________________
n=int(input("Enter the number: "))
product=1
for i in range(1,n+1):
product*=i
print("The factorial will be : ", product)
______________________________
Answered by
8
Required program :-
class factorial
{
void main (int n)
{
int , f = 1 , i ;
for (i = 1 , i < = n , i++ )
{
f = f * i
}
System.out.println ("Factorial is "+ f ) ;
}
}
Explanation :-
- Line 3 : A variable that is n is inputted
- Line 5 : f is factorial of a number (n) and (i) is the loop of variable (n)
- Line 6 : Loop is runned.
- Line 8 : Factorial is being calculated.
- Line 11 : Factorial is displayed.
Similar questions