fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int A[10][10]={0},B[10][10]={0},C[10][10]={0}, nf=0, nc=0;
  8. cout<<"#Rows: "<<endl;
  9. cin>>nf;
  10. cout<<"#Columns: "<<endl;
  11. cin>>nc;
  12.  
  13.  
  14. //For the A part
  15. for(int i=0; i<nf;i++){
  16.  
  17. for(int j= 0; j<nc;j++){
  18.  
  19. cin>>A[i][j];
  20. }}
  21.  
  22. //For the B part
  23. for(int i=0; i<nf;i++){
  24.  
  25.  
  26. for(int j= 0; j<nc;j++){
  27.  
  28. cin>>B[i][j];
  29. }}
  30.  
  31.  
  32. //Calculation
  33. for(int i=0; i<=nf;i++)
  34. for(int j=0;j<=nc;j++)
  35. C[i][j]= A[i][j]+ B[i][j];
  36.  
  37.  
  38. //output
  39. for(int i=0; i<nf;i++)
  40. {for(int j=0;j<nc;j++)
  41. cout<<C[i][j]<<" ";
  42. cout<<endl;
  43. }
  44. }
Success #stdin #stdout 0.01s 2728KB
stdin
2
2
1
2
3
4
1
2
3
4
stdout
#Rows: 
#Columns: 
2  4  
6  8