I need a function that will return the opposite of a number, but i also need to be able to specify the 'center'.
eg. Center = 0. If the number was 10, it would return -10.
I need this: Center = 100. If the number was 10, it woul开发者_运维技巧d return 190.
Any idea how it could be done?
Thanks.
-(int) returnOppositeOf:(int)myNumber aroundCenter:(int)center
{
return ( (center*2) - myNumber);
}
Opposite = 2 * Center - X
opp = center - (x - center)
精彩评论