You are viewing a single comment's thread. Return to all comments →
I didnot include any extraneous libraries, I did my code in c++,kindly help me...thank you for your time and help my code:
using namespace std; void sum(int[][6]); int main() { int a[6][6]; int i,j; cout<<"enter val\n"; for(i=0;i<6;i++) { for(j=0;j<6;j++) { cin>>a[i][j]; } } sum(a); return 0; } void sum(int a[][6]) { int l=0,m=0; int i,j,max; int sum[4][4]; for(i=0,j=0;i<=3,j<=3;j++) { if(j==3) { sum[l][m]=a[i][j]+a[i][j+1]+a[i][j+2]+a[i+1][j+1]+a[i+2][j]+a[i+2][j+1]+a[i+2][j+2]; i++; j=-1; } else { sum[l][m]=a[i][j]+a[i][j+1]+a[i][j+2]+a[i+1][j+1]+a[i+2][j]+a[i+2][j+1]+a[i+2][j+2]; } m++; if(m==4) { l++; m=0; } } max=sum[0][0]; for(i=0;i<4;i++) { for(j=0;j<4;j++) { if(sum[i][j]>=max) { max=sum[i][j]; } } } cout<<"max"<
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
I didnot include any extraneous libraries, I did my code in c++,kindly help me...thank you for your time and help my code:
include
using namespace std; void sum(int[][6]); int main() { int a[6][6]; int i,j; cout<<"enter val\n"; for(i=0;i<6;i++) { for(j=0;j<6;j++) { cin>>a[i][j]; } } sum(a); return 0; } void sum(int a[][6]) { int l=0,m=0; int i,j,max; int sum[4][4]; for(i=0,j=0;i<=3,j<=3;j++) { if(j==3) { sum[l][m]=a[i][j]+a[i][j+1]+a[i][j+2]+a[i+1][j+1]+a[i+2][j]+a[i+2][j+1]+a[i+2][j+2]; i++; j=-1; } else { sum[l][m]=a[i][j]+a[i][j+1]+a[i][j+2]+a[i+1][j+1]+a[i+2][j]+a[i+2][j+1]+a[i+2][j+2]; } m++; if(m==4) { l++; m=0; } } max=sum[0][0]; for(i=0;i<4;i++) { for(j=0;j<4;j++) { if(sum[i][j]>=max) { max=sum[i][j]; } } } cout<<"max"<