## Introduction

Factorial is a mathematical operation that calculates the product of all positive integers less than or equal to a given number. A factorial of a non-negative integer, n, is the product of all positive integers less than or equal to n. For example, the factorial of 5 is 120. This basic but powerful concept is crucial in areas such as permutations & combinations, algorithms, & statistical calculations.

In programming, factorial programs are commonly used to find the factorial value of a number. In this article, we will learn how to implement a factorial program in C++ using both loops & recursion.

## Factorial Program Using a Loop

To compute the factorial of a number using a loop in C++, we utilize a simple for loop that multiplies numbers successively. This approach is straightforward & effective for calculating factorials of smaller numbers. Hereâ€™s how you can do it:

First, you need to include the standard input-output library in your C++ program, which is done by adding #include <iostream> at the beginning of your code. This allows you to use input & output operations in your program.

Here's a basic example of calculating the factorial of a number using a loop:

Output

```
Enter a positive integer: 5
Factorial of 5 = 120
```

In this code:

- We start by declaring an integer n that will store the number for which we want to find the factorial.

- We also declare factorial & initialize it to 1. This variable will store the result of the factorial.

- The program then prompts the user to enter a positive integer.

- It uses a for loop where i starts from 1 & increments by 1 until it reaches n. In each iteration of the loop, factorial is multiplied by i.

- After the loop completes, the factorial of the number is printed.

This loop-based method is simple & efficient for inputs that are not excessively large, as the value of factorial grows very quickly & can exceed the storage capacity of standard data types for large inputs.