Program to Find Factorial

#include "iostream"
using namespace std;
void main() {
int n;
cout << "Enter a positive integer: ";
cin >> n;
int factorial =1;
for(int i = 1; i <=n ; i++)
{
factorial = factorial * i;
}
cout << "Factorial of " << n << " = " << factorial;

}
Output
Enter a positive integer: 5
Factorial of 5 = 120

Post a Comment

0 Comments