Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
596 views
in Technique[技术] by (71.8m points)

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

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 following error:


'Mathematics.exe': Loaded 'C:Documents and SettingsmbryantMy DocumentsVisual Studio 2010ProjectsMathematicsDebugMathematics.exe', Symbols loaded. 'Mathematics.exe': Loaded 'C:WINDOWSsystem32 tdll.dll', Cannot find or open the PDB file 'Mathematics.exe': Loaded 'C:WINDOWSsystem32kernel32.dll', Cannot find or open the PDB file 'Mathematics.exe': Loaded 'C:WINDOWSsystem32msvcp100d.dll', Symbols loaded. 'Mathematics.exe': Loaded 'C:WINDOWSsystem32msvcr100d.dll', Symbols loaded. The thread 'Win32 Thread' (0x6ec) has exited with code -1073741510 (0xc000013a).

The program '[6072] Mathematics.exe: Native' has exited with code -1073741510 (0xc000013a).

Here is the code:

#include <iostream>
using namespace std;
bool isPrime(int x){
    int b = 0;
    int i = 2;
    if(x == 2){
    return 1;
    }
    if (x > 2){
        while(i < x){
            if ( (x % i) != 0){
            b = b + 1;
            i = i + 1;
            }

        }
        if (b > 0){
        return 1;
        } if (b == 0){
        return 0;
        }




    }

}
int main(){
    cout << isPrime(9) << endl;
    system("pause");
    return 0;
}

Helping with resolving this issue would be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...