小编Gam*_*afa的帖子

C ++表达式必须具有恒定值

我已经用dev c ++编写了此代码,并且可以工作,但是当我尝试在Visual Studio中运行它时,会出现错误,例如expression必须具有恒定值

#include <iostream>
using namespace std;

int main() {
    int r, c, j;
    int matrix[r][c];
    cout << "Enter the size of matrix: ";
    cin >> j;

    for (r = 0; r < j; r++) {
        for (c = 0; c < j; c++) {
            cout << "matrix" << "[" << r << "]" << "[" << c << "] = ";
            cin >> matrix[r][c];
        }
    }

    cout << "\n";
    for (int i = 0; i …
Run Code Online (Sandbox Code Playgroud)

c++ arrays dev-c++ multidimensional-array visual-studio

2
推荐指数
1
解决办法
98
查看次数

Sum of the elements of diagonal of matrix c++

I want to find the sum of the diagonals of matrix that defined by user with this code , it works for main diagonal but not for secondary diagonal and i don't understand what the problem is. Any help would be appreciated.

#include <iostream>
using namespace std;

int main() {
    int r, c, j,i,k,sum1,sum2;
    cout << "Enter the size of matrix: ";
    cin >> j;
    int matrix[j][j];

    for (r = 0; r < j; r++) {
        for (c = 0; …
Run Code Online (Sandbox Code Playgroud)

c++ loops for-loop vector visual-studio

1
推荐指数
1
解决办法
80
查看次数