简体   繁体   English

运行时检查失败#2 - 变量'B'周围的堆栈已损坏

[英]Run-Time Check Failure #2 - Stack around the variable 'B' was corrupted

this error keeps coming up yet i dont see a problem with the code (its in c++) the program is supposed to find the inverse of a 2x2 matrix 这个错误不断出现但我没有看到代码的问题(在c ++中)该程序应该找到2x2矩阵的逆

#include <iostream>

using namespace std;

int main() { 
    float d;
    float A[2][2], B[2][2];

    do {
        cout << "please enter valid parameters in for 11,12,21,22" << endl;

        for(int i = 0; i < 2; i++) {
            for(int j = 0; j < 2; j++)
                cin >> A[i][j];
        }

        d = (A[1][1] * A[2][2]) - (A[1][2] * A[2][1]);
    } while(d == 0);

    B[1][1] = A[2][2] * (1.0 / d);
    B[1][2] = A[1][2] * (-1.0 / d);
    B[2][1] = A[2][1] * (-1.0 / d);
    B[2][2] = A[1][1] * (1.0 / d);

    for(int k = 0; k < 2; k++) {
        for(int h = 0; h < 2; h++) 
            cout << B[k][h] << " ";
        cout << endl;
    }

    return 0;
}

您将B和A从1索引到2,而不是从0到1使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行时检查失败 #2 - 变量“IDNumber”周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'IDNumber' was corrupted 运行时检查失败#2-变量&#39;indices&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'indices' was corrupted 运行时检查失败#2-变量&#39;result&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'result' was corrupted 运行时检查失败#2-变量&#39;numberchoices&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'numberchoices' was corrupted 运行时检查失败#2-变量&#39;ex&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'ex' was corrupted 运行时检查失败#2-变量&#39;NearID&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'NearID' was corrupted 运行时检查失败-变量周围的堆栈已损坏 - Run-Time Check Failure - Stack around variable was corrupted 运行时检查失败#2-变量&#39;s&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 's' was corrupted 运行时检查失败#2-变量周围的堆栈-已损坏 - Run-Time Check Failure #2 - Stack around the variable — was corrupted 运行时检查失败 #2 - 变量“newRow”周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'newRow' was corrupted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM