What to do for running the factorial for the number 100 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What to do for running the factorial for the number 100

when i enter short numbers such as 10 it gives right answer but when i insert 100 it gives us negative value https://code.sololearn.com/cubUgpUKWskX/?ref=app

7th Nov 2018, 6:53 AM
Walker
Walker - avatar
3 Answers
7th Nov 2018, 9:50 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
You can use a bigger number type, for example 'unsigned long long' instead of 'int'. Then you can handle larger numbers; but not 100! - the numbers get too large very quickly. What you can do: Write a program that calculates the number digit by digit and stores them in an array. You can see an example in this code (although yours will be harder (and in this case they aren't stored but just couted)): https://code.sololearn.com/cz7MX8k6RK0d/?ref=app
7th Nov 2018, 7:33 AM
HonFu
HonFu - avatar
+ 2
Try float fact but the output will be in sientific notation and becomes to great to handle so that it gives inf for bigger nums what i think stands for infinity
7th Nov 2018, 7:34 AM
Mbrustler
Mbrustler - avatar