Can someone explain elements of factorial and function of factorial

I know how to wire a code but i dont fully understand the elements of factorial code.


int b, a, factorial=1;
cout <<"Enter number: ";
cin >>b;
for (a=1; a<=b; a++)
{
factorial = factorial*a;
}
cout <<factorial;


Put the code you need help with here.
#include <iostream>

using namespace std;
int factorial (int c, int d=1)
{
for (int i=2; i<=c; i++)
{
d=d*i;
}
return d;
}

int main()
{
int a, b;
cout <<"Enter number: ";
cin >>a;
b=factorial(a);
cout <<"Factorial is: " <<b;

return 0;
}
Topic archived. No new replies allowed.