我已经用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) 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)