+ 3

what's the problem???!

the code below works well for number less than 20 but is goes weird for greater than 20 https://code.sololearn.com/cyWGWca3R3Rd/?ref=app

7th Jun 2020, 9:38 AM
hamid
hamid - avatar
6 odpowiedzi
+ 4
Because factorial of number larger than 20 does not fit in the size of (int). You have to use a larger datatype for that.
7th Jun 2020, 9:44 AM
Arsenic
Arsenic - avatar
+ 3
what do you mean?how should I use a larger datatype?
7th Jun 2020, 10:45 AM
hamid
hamid - avatar
+ 3
hamid size of (int) data type is 4bytes which means it can store only value upto 2,147,483,647 To store larger numbers you should go for the datatype with much larger range for example *long* which is double the size of int(long is of 8bytes) , it can store upto 9,223,372,036,854,775,807 But this limit will soon be short because of drastic increase in factorials, so for even larger numbers you should go for arrays
7th Jun 2020, 11:52 AM
Arsenic
Arsenic - avatar
+ 3
thank you so much 👍👍 but Is using arrays give us the largest datatype?there is no larger than that?
7th Jun 2020, 1:11 PM
hamid
hamid - avatar
+ 3
hamid array is a collection of elements of specific datatype, which gives you freedome to allocate a huge amount of space also.
7th Jun 2020, 1:38 PM
Arsenic
Arsenic - avatar
7th Jun 2020, 6:01 PM
zemiak