+ 1
Why this code return negative result ???????
9 Respostas
+ 1
It's range is exceeding Integer range.
For value 20...
So maximum integer value +1 = minimum integer value..
Count goes from min negative value....
+ 4
beause 20! is equal to
2432902008176640000
which is bigger than the maximum value int data type can hold
https://www.w3schools.com/cs/cs_data_types.asp
+ 2
It's because the dataype is integer which store only 4byet you need to cast it to long or other data type
+ 1
But why it works correctly for 25
25 bigger than 20 ??????
+ 1
That's not the correct answer.
Integers can be stored in only 4bytes.
And max value of Integer is 2147483647.
And 1 to this Integer number you get -2147483648.
So if 20! is equal to
2432902008176640000
which is bigger than the maximum value int data type can hold, it showing only first 4bytes value here.
static int ma(int x)
{
if(x == 1)
{
return 1;
}
return x * ma(x - 1);
}
static long ma(long x)
{
if(x == 1)
{
return 1;
}
return x * ma(x - 1);
}
static void Main(string[] args)
{
Console.WriteLine(ma(20)); //int 20
Console.WriteLine(ma(20L));//long 20
}
Mohammad
Run this code and see difference...
0
Ok i understand
0
How do you mentioned me
I cant mentioned
i don't how
0
While writing, Press @ and select name.
There you can see all follower of this thread, all your followers, whom you following...
Mohammad
0
Oh my god
Thanks