Here is source code of the C++ program which computes the factorial of a given number. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ program to compute factorial of a given integer
using namespace std;
long long val = 1;
cin >> fac;
cout << endl;
for (int i = 2; i <= fac; i++)
val = val * i;
cout << "The factorial of " << fac << " is " << val << endl;
$ g++ main.cpp $ ./a.out Enter the integer : 10 The factorial of 10 is 3628800
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.