i have this task to read two 2D arrays and put the sum in third array. i dont get it why this codes not working.please help.
#include<iostream>
using namespace std;
void main ()
{
int arr1[3][3],arr2[3][3],ans[3][3],i,j,k,m;
cout<<"enter the enteries of first 3x3 array"<<endl;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>arr1[i][j];
cout<<"enter the enteries of second 3x3 array"<<endl;
for(k=0;k<3;k++)
for(m=0;m<3;m++)
cin>>arr2[i][j];
for(i=0,k=0;i<3,k<3;i++,k++)
for(j=0,m=0;j<3,m<3;j++,m++)
if((i==k)&&(j==m))
{
ans[i][j]=arr1[i][j]+arr2[k][m];
#include<iostream>
usingnamespace std;
void main ()
{
int arr1[3][3],arr2[3][3],ans[3][3],i,j,k,m;
cout<<"enter the enteries of first 3x3 array"<<endl;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>arr1[i][j];
cout<<"enter the enteries of second 3x3 array"<<endl;
for(k=0;k<3;k++)
for(m=0;m<3;m++)
cin>>arr2[i][j];
for(i=0,k=0;i<3,k<3;i++,k++)
for(j=0,m=0;j<3,m<3;j++,m++)
if((i==k)&&(j==m))
{
ans[i][j]=arr1[i][j]+arr2[k][m];
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cout<<ans[i][j]<<endl;
}
these are the two 2D arrays. first is [i][j] and second is [k][m]. my problem is i am not geeting the sum in the end.
if i input 1 for all the entries for both 2D arrays i am not getting 2 as the sum.