+ 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
6 odpowiedzi
+ 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/
+ 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.
+ 1
when the number reach the upper limit (INT_MAX) it'll loop back and start again from the lowest possible value (INT_MIN)
+ 1
That is a so-called integer overflow:
https://en.m.wikipedia.org/wiki/Integer_overflow
0
Tnx for ur answeres but the thing is why does it show a negetive number when we use int
0
Oooh it makes sense now😂
Thank u all