✅ Explanation:
1. Initialization
We start with total set to 1.
2. Loop Execution
This means i will take values: 1, 2, 3, 4 (the number 5 is not included).
3. Loop Body
This is shorthand for:
It multiplies total by the current i.
Step-by-Step Calculation:
| i | total before | total after |
|---|---|---|
| 1 | 1 | 1×1 = 1 |
| 2 | 1 | 1×2 = 2 |
| 3 | 2 | 2×3 = 6 |
| 4 | 6 | 6×4 = 24 |
Final Output:
➡️ 24 is printed.
Summary:
This code calculates the factorial of 4:
4! = 1 × 2 × 3 × 4 = 24


0 Comments:
Post a Comment