Broken calculator-failed some test cases

code: #include
using namespace std;
int main() {
long long int n;
cin>>n;
long long int cnt=1;
for(int i=n;i>0;i–)
{
cnt=cnt*i;
}
cout<<cnt;
return 0;
}

Hey @vashishthkuntal.gajjar2019 you will be having value of N in range of 1 to 500,
factorial of 100 is

100 !  = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

No data type can store this much value as the logic you are using, won’t be applicable in solving this problem. So you have to think differently in this problem.
Think somewhat in this direction

A number 5189 is stored in res[] as following.
res[] = {9, 8, 1, 5}
x = 10

Initialize carry = 0;

i = 0, prod = res[0]*x + carry = 9*10 + 0 = 90.
res[0] = 0, carry = 9

i = 1, prod = res[1]*x + carry = 8*10 + 9 = 89
res[1] = 9, carry = 8

i = 2, prod = res[2]*x + carry = 1*10 + 8 = 18
res[2] = 8, carry = 1

i = 3, prod = res[3]*x + carry = 5*10 + 1 = 51
res[3] = 1, carry = 5

res[4] = carry = 5

res[] = {0, 9, 8, 1, 5}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.