How do you mean when you "insert it". Surely just having it as part of your code wouldn't crash your program. There must be some function using the result of median where the crash is occurring, because there doesn't seem to be anything that would crash the program within the function itself.
It is not the function that crashes your program. It is your code that you did not show that crashes the program.:)
As for the function then it of course can be rewritten that to look more professional.
1 2 3 4
inlineint median( int r )
{
return ( r / 2 + r % 2 );
}
the median function is wrong since when the array is split lets say on element 4 and 6, I'm passing it the 6 instead then asking it for the median between 6 and 0, which would be out of range.