I was solving an algorithm and everything worked on my computer, the answer result is as what the question is saying
Main.cpp: 5:15: error: variable-sized object may not be initialized
int array_2d [r] [c] = {{1, 5, 6},
^ ^
Is there anything I could do to fix this? I am somewhat new to the algorithm solving challenges that are on the websites.
#include<iostream>
using namespace std;
int main(){
int c=3,r=3;
int array_2d[r][c]={{1, 5, 6},
{8, 2, 7},
{3, 4, 9}};
int sum_row[c*r];
int sum_col[c*r];
int Max_total;
int num_digit=2;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(array_2d[i][j+1])
{
sum_row[i*c+j]=array_2d[i][j]*10+array_2d[i][j+1];
}else{
sum_row[i*c+j]=array_2d[i][j];
}
}
}
for(int i = 0;i < 9; ++i) {
if(sum_row[0] < sum_row[i]){
sum_row[0]=sum_row[i];
}
};
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(array_2d[j+1][i]){
sum_col[i*c+j]=array_2d[j][i]*10+array_2d[j+1][i];
}else{
sum_col[i*c+j]=array_2d[j][i];
}
}
}
for(int i = 0;i < c*r; ++i) {
if(sum_col[0] < sum_col[i])
sum_col[0]=sum_col[i];
}
if(sum_row[0] > sum_col[0]){
Max_total=sum_row[0];
}
else{
Max_total=sum_col[0];
}
cout<<"Max "<<Max_total<<endl;
}