+ 1

Why does the factoriel function in yhis code doesnt work properly for big numbers?

Hey guys could u please have a look at this code and tell me what is going wrong? https://code.sololearn.com/cmERjMyJz5eR/?ref=app

23rd Oct 2019, 3:57 AM
Emad
6 Respuestas
+ 3
Because the data type integer is limited to a shorter range of numbers. long long int works here: https://code.sololearn.com/cBLZuKvEs67t/?ref=app Here is a table with some more information on max values of in, long int etc. : https://www.zentut.com/c-tutorial/c-integer/
23rd Oct 2019, 4:28 AM
Thoq!
Thoq! - avatar
+ 3
#include<limits.h> Integers(int) are bounded by INT_MIN and INT_MAX, use INT_MAX to see max value int can store you will see fact(16) will be below it, but fact(17) onwards it will be bigger than INT_MAX value.
23rd Oct 2019, 4:43 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
when the number reach the upper limit (INT_MAX) it'll loop back and start again from the lowest possible value (INT_MIN)
23rd Oct 2019, 5:19 AM
Taste
Taste - avatar
+ 1
That is a so-called integer overflow: https://en.m.wikipedia.org/wiki/Integer_overflow
23rd Oct 2019, 5:22 AM
Thoq!
Thoq! - avatar
0
Tnx for ur answeres but the thing is why does it show a negetive number when we use int
23rd Oct 2019, 4:55 AM
Emad
0
Oooh it makes sense now😂 Thank u all
23rd Oct 2019, 9:09 AM
Emad