Exchange 1000s digit with 10s digit (C)

前端 未结 3 1959
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-16 10:45

I am trying to switch for example: input 54321.987, then 4 and 2 should switch, so output would be 52341.987. 54321.777 should become 52341.777. If it is 2345.777 it should

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-16 11:21

    I just wrote this:

    double swapDigits(double in)
    {
        return in + ((int)(in / 10) % 10 - (int)(in / 1000) % 10) * 990.0;
    }
    

提交回复
热议问题