Program to Calculate the Factorial of any Number using for loop - C++ Programming
Calculate the Factorial of any Number:
Program:
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the value of n" << endl;
cin >> n;
int fact = 1;
for (int i=1 ; i<=n ; i++)
{
fact = fact*i;
}
cout << "fact = " << fact << endl;
return 0:
}
Program:
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the value of n" << endl;
cin >> n;
int fact = 1;
for (int i=1 ; i<=n ; i++)
{
fact = fact*i;
}
cout << "fact = " << fact << endl;
return 0:
}
Comments
Post a Comment