开发者

Get opposite of number if middle is not zero

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜