开发者

Get opposite of number if middle is not zero

开发者 https://www.devze.com 2023-01-13 02:51 出处:网络
I need a function that will return the opposite of a number, but i also need to be able to specify the \'center\'.

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

精彩评论

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

关注公众号