C++ Example - Factorial of a Number
The factorial of a positive integer (English: factorial) is the product of all positive integers less than or equal to that number, and 0! equals 1. The factorial of a natural number n is written as n!.
Example
include
<
iostream
using
namespace
std;
int
main
(
)
{
unsigned
int
n
;
unsigned
long
long
factorial
=
1
;
cout
<<
"
Enter an integer:
"
;
cin
n
;
for
(
int
i
=
1
;
i
<=
n
; ++
i
)
{
factorial
*=
i
;
}
cout
<<
n
<<
"
factorial is:
"
<<
"
=
"
<<
factorial
;
return
0
;
}
The output of the above program is:
输入一个整数: 12
12 的阶乘为: = 479001600
C++ Example