Write a program to print factorial of n number in c++

Write a program to print factorial of n numbers in c++. Here’s the sample program for factorial number in c++ for beginners in programming language. This program will help you to find the factorial in C++ programming language.

#include <iostream>
using namespace std;
int main()
{
int n;
long long fact = 1;
cout << "Enter a positive integer: ";
cin >> n;
for(int i = 1; i <=n; ++i)
{
fact *= i;
}
cout << "fact of " << n << " = " << fact; 
return 0;
}

Output:

Enter a positive integer: 5

fact of 5 = 120

What is factorial in c++ programming

The product of all positive integers less than or equal to a particular positive integer, represented by that integer and an exclamation point in mathematics. As a result, factorial seven is expressed as 7!, which means 1 2 3 4 5 6 7. The factorial zero is equal to one.