C++ Program to Find Factorial of n using For Loop
Write C++ Program to Find Factorial of n using For Loop
// CPP Program to Find Factorial of n using For Loop #include <iostream> using namespace std; int main() { int n, i, fact = 1; cout << "Enter the number :--> "; cin >> n; for(i = 1; i<=n; i++) { fact = fact * i; } cout << "The factorial of " << n << " is " << fact; return 0; }
Output:
Enter the number :--> 6
The factorial of 6 is 720