C++ Program to Find Factorial of a Number Using For Loop

Factorial of n number in c++. Here’s the sample program for factorial number in c++ for beginners in 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

Factorial in C++

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.

Return Statement in C++

A return statement terminates a function’s execution and returns control to the caller function.

At the point immediately following the call, execution restarts in the caller function. A return statement can return a value to the function that called it.

A return statement terminates a function’s execution and returns control to the caller function.

At the point immediately following the call, execution restarts in the caller function. A return statement can return a value to the function that called it.