Here I have shared the factorial program in C++. A Factorial is the product of a number and all the numbers below it.
For example, the factorial of 4! = 4 × 3 × 2 × 1 = 24.
#include<iostream> using namespace std; int main() { unsigned long i,fac,n; cout<<"Enter number: "; cin>>n; for(i=1,fac=1;i<=n;++i) { fac=i*fac; } cout<<"Factorial of "<<n<<" is: "<<fac; return 0; }
Output:
Enter number: 5
Factorial of 5 is: 120
If you have any problem regarding the below factorial program in C++ then you can freely ask it by commenting below.
for(i=1;i<n;i++)
{
fac=n(n-i);
n=fac;
}
this logic will also give the same result ……
problem solved! thanks,
Write a program in c++ to read a single dimension array of size 'n' and create a 2-d array as follows:
input array: 1 2 3 4
output array: 1 0 0 1
0 2 2 0
0 3 3 0
4 0 0 4