Native exiting with with code: -1073741510 (0xc000013a) while using prime checker function

前端 未结 1 1872
广开言路
广开言路 2020-12-10 17:56

I have been trying to create my own prime checker function, although strangely when I call isPrime(7) it returns 1, which is good, but when I call isPrime(9) it gives me the

相关标签:
1条回答
  • 2020-12-10 18:33

    According to:

    Jobs failing on Windows with Exit Code 0xC000013A

    Globally speaking, Exit Code 0xC000013A means that the application terminated as a result of a CTRL+C or  closing command prompt window

    I copied, compiled and ran your code. With x=9, the code is stuck in the while loop forever, so I had to close the program using the close button ([x] button in the upper right corner). That generated the 0xc000013a error code. (With x=7 the program is not stuck in the while loop so it is able to exit normally.)

    More specifically, for x=9 the program is stuck in the while loop because when i=3 then (x % i) == 0 (9 mod 3 = 0) and the statement i = i + 1 never executes. So i never increments beyond 3 and i < x (3 < 9) is always true.

    So the immediate problem is that your code never exits (for x=9) and you have to stop it, presumably by clicking the close button. But the larger issue is that your logic is bad and your program isn't working the way you think it is.

    For example, when x=9 and i=2, then (x % i) != 0 and that leads to b = b + 1. That means b > 0 and your program should return 1, which you indicated meant prime in the case of x=7. But 9 is not prime.

    Also, isPrime has a return type of bool but you are returning int.

    0 讨论(0)
提交回复
热议问题