windows - native 退出,代码为 : -1073741510 (0xc000013a) while using prime checker function

标签 windows exit-code

我一直在尝试创建我自己的素数检查器函数,虽然奇怪的是当我调用 isPrime(7) 时它返回 1,这很好,但是当我调用 isPrime(9) 时它给我以下错误:


“Mathematics.exe”:已加载“C:\Documents and Settings\mbryant\My Documents\Visual Studio 2010\Projects\Mathematics\Debug\Mathematics.exe”,已加载符号。 “Mathematics.exe”:已加载“C:\WINDOWS\system32\ntdll.dll”,无法找到或打开 PDB 文件 “Mathematics.exe”:已加载“C:\WINDOWS\system32\kernel32.dll”,无法找到或打开 PDB 文件 “Mathematics.exe”:已加载“C:\WINDOWS\system32\msvcp100d.dll”,已加载符号。 “Mathematics.exe”:已加载“C:\WINDOWS\system32\msvcr100d.dll”,已加载符号。 线程“Win32 线程”(0x6ec) 已退出,代码为 -1073741510 (0xc000013a)。

程序“[6072] Mathematics.exe: Native”已退出,代码为 -1073741510 (0xc000013a)。

代码如下:

#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;
}

帮助解决此问题将不胜感激。

最佳答案

根据:

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

我复制、编译并运行了您的代码。与 x=9 , 代码卡在 while 中永远循环,所以我不得不使用关闭按钮(右上角的 [x] 按钮)关闭程序。这生成了 0xc000013a 错误代码。 (使用 x=7 程序不会卡在 while 循环中,因此可以正常退出。)

更具体地说,对于 x=9该程序卡在 while 中循环因为当i=3然后 (x % i) == 0 (9 mod 3 = 0) 和语句 i = i + 1从不执行。所以i永远不会超过 3 和 i < x (3 < 9) 始终为真。

所以直接的问题是您的代码永远不会退出(对于 x=9 )并且您必须停止它,大概是通过单击关闭按钮。但更大的问题是你的逻辑不好,你的程序没有按照你认为的方式工作。

例如,当x=9i=2 , 然后 (x % i) != 0这导致b = b + 1 .这意味着 b > 0并且您的程序应该返回 1,您表示在 x=7 的情况下这意味着素数.但是 9 不是质数。

此外,isPrime返回类型为 bool但你回来了int .

关于windows - native 退出,代码为 : -1073741510 (0xc000013a) while using prime checker function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45691954/

相关文章:

c++ - C++ "was not declared in scope"中的 beep() 函数

windows - 如何动态选择音频设备?

bash - 启动独立的作业步骤并跟踪最高退出代码

android - 错误 : resizing partition e2fsck failed with exit code 8

iphone - 当我没有互联网连接并通过 Appstore 测试时,我可以在 IOS 上使用 Exit(0) 功能吗?

c# - 获取 OEM 和 Ansi 中每个语言环境的代码页

windows - 意外关闭后,如果持久数据被删除,RabbitMQ只能启动

android - 设置gradle临时目录为SSD

powershell - 为什么Powershell在Windows 7上不返回ExitCode

powershell - 如何防止主机退出并返回退出代码?