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 );