Factorial of a Number in C++
Today we write Factorial Program in C++. It is very simple and easy. Factorial of any number means the product of a number and below it. For example factorial of 6 is; 6*5*4*3*2*1 = 720
Program Code
#include <iostream>
using namespace std;
int main()
{
int i, n, factorial = 1;
cout<<"Enter any positive integer: ";
cin>>n;
for (i = 1; i <= n; ++i)
{
factorial= factorial* i;
}
cout<< "Factorial of "<<n<<" = "<<factorial;
return 0;
}
Output:
Enter any positive integer: 6
Factorial of 6 = 720
I hope this code is helpful for you. You can also download this code from our website Tutroal4us.com
No comments:
Post a Comment