search

Home  >  Q&A  >  body text

c++ - 整数和浮点数的相互转化运算的问题?

将for循环里面的 double 换成 int 就不能运行了

这就是将double 换成 int 后的结果了

迷茫迷茫2803 days ago567

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-17 13:40:03

    is no problem originally, but the n and m you input here are too large, and the integer overflows, causing i * i to become 0 after overflow, and a division-by-zero exception in the denominator occurs.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:40:03

    1/(i*i) is the division of two integers (in this case, 1/3 is not equal to 0.3333... but equal to 0), I think you need to use 1.0/(i*i) for this. Since i*i may indeed be 0, you'd better judge ahead of time.

    reply
    0
  • Cancelreply