Find Factorial of Number
C++
Medium
4 views
Problem Description
Find factorial of N. Example: 5! = 5×4×3×2×1 = 120
Real Life: Used in probability and permutation calculations.
Step-by-Step Logic:
1. Take number N
2. Start result = 1
3. Multiply result with all numbers from N down to 1
4. Print final result
Official Solution
void control_q8_factorial() {
int n = 6;
int factorial = 1;
for(int i = n; i >= 1; i--) {
factorial = factorial * i;
}
cout << "Factorial of " << n << " is: " << factorial << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!