---------------------------------------------------------------------------------------------------------------------
Factorial without Recursion Try It🔻
---------------------------------------------------------------------------------------------------------------------
You can find factorial of maximum number 25 with long type. If you cross the limit then you start getting Negative Values .
---------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
long num,factorial=1;
cout<<"Enter Number To Find Its Factorial: ";
cin>>num;
cout<<endl<<"Factorial of Given Number is : ";
for(long a=1;a<=num;a++)
{
factorial=factorial*a;
if(a<=num-1)
cout<<a<<" * ";
else
cout<<a<<" = "<<factorial;
}
return 0;
}
---------------------------------------------------------------------------------------------------------------------
OUTPUT Try It🔻
---------------------------------------------------------------------------------------------------------------------Enter Number To Find Its Factorial: 25
Factorial of Given Number is : 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 * 21 * 22 * 23 * 24 * 25 = 7034535277573963776
Factorial without Recursion Try It🔻
---------------------------------------------------------------------------------------------------------------------
You can find factorial of maximum number 25 with long type. If you cross the limit then you start getting Negative Values .
---------------------------------------------------------------------------------------------------------------------
using namespace std;
int main()
{
long num,factorial=1;
cout<<"Enter Number To Find Its Factorial: ";
cin>>num;
cout<<endl<<"Factorial of Given Number is : ";
for(long a=1;a<=num;a++)
{
factorial=factorial*a;
if(a<=num-1)
cout<<a<<" * ";
else
cout<<a<<" = "<<factorial;
}
return 0;
}
---------------------------------------------------------------------------------------------------------------------
OUTPUT Try It🔻
---------------------------------------------------------------------------------------------------------------------Enter Number To Find Its Factorial: 25
Factorial of Given Number is : 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20 * 21 * 22 * 23 * 24 * 25 = 7034535277573963776