Create a program that will compute and display for the factorial of N wherein N is a positive integer entered by the user.
•The formula for factorial is N * (N-1) * (N-2) * (N-(N-1)). For example, the factorial of 5 is 5 * 4 * 3 * 2 * 1.
Share
Create a program that will compute and display for the factorial of N wherein N is a positive integer entered by the user.
•The formula for factorial is N * (N-1) * (N-2) * (N-(N-1)). For example, the factorial of 5 is 5 * 4 * 3 * 2 * 1.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
in Python languange, there is two different way to find the factorial of N
Python #1:
n = int(input("Enter: "))
result = 1
for i in range(1, n + 1):
result *= i
print(result)
Python #2:
from math import factorial
n = int(input("Enter: "))
print(factorial(n))
Since hindi ka nag bigay ng specific programming languange, nag create din ako for C++ PL
C++:
#include <iostream>
using namespace std;
int main(){
int n;
int factorial = 1;
cout << "Enter n: ";
cin >> n;
for (int i = 1; i <= n; i++) {
factorial = factorial * i;
}
cout << factorial << endl;
return 0;
}