C++ Example - Finding the Factorial of a Number

C++ Examples

The factorial of a positive integer (English: factorial) is the product of all positive integers less than or equal to that number, and the factorial of 0 is 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 << "'s factorial is:"<< " = " << factorial; return 0; }

The output result of the above program execution is:

输入一个整数: 12
12 的阶乘为: = 479001600

C++ Examples

other extensions