本机退出代码:-1073741510(0xc000013a),同时使用素数检查器功能 [英] Native exiting with with code: -1073741510 (0xc000013a) while using prime checker function

查看:97
本文介绍了本机退出代码:-1073741510(0xc000013a),同时使用素数检查器功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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':已加载 'C:\Documents and Settings\mbryant\My Documents\Visual Studio 2010\Projects\Mathematics\Debug\Mathematics.exe',已加载符号.'Mathematics.exe': Loaded '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).

'Mathematics.exe': Loaded 'C:\Documents and Settings\mbryant\My Documents\Visual Studio 2010\Projects\Mathematics\Debug\Mathematics.exe', Symbols loaded. 'Mathematics.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file 'Mathematics.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file 'Mathematics.exe': Loaded 'C:\WINDOWS\system32\msvcp100d.dll', Symbols loaded. 'Mathematics.exe': Loaded 'C:\WINDOWS\system32\msvcr100d.dll', Symbols loaded. The thread 'Win32 Thread' (0x6ec) has exited with code -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;
}

非常感谢您帮助解决此问题.

Helping with resolving this issue would be greatly appreciated.

推荐答案

据:

Windows 上的作业失败,退出代码为 0xC000013A

从全局来看,退出代码 0xC000013A 表示应用程序因 CTRL+C 或关闭命令提示符窗口而终止

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 循环中,因此可以正常退出.)

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.)

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

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.

所以当前的问题是您的代码永远不会退出(对于 x=9),您必须停止它,大概是通过单击关闭按钮.但更大的问题是你的逻辑很糟糕,你的程序没有按照你想象的方式工作.

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.

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

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.

此外,isPrime 的返回类型为 bool,但您返回的是 int.

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

这篇关于本机退出代码:-1073741510(0xc000013a),同时使用素数检查器功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆