[ create a new paste ] login | about

Link: http://codepad.org/s9pNKx9N    [ raw code | output | fork ]

C, pasted on Mar 10:
#include<stdio.h>
#define R 2
#define C 2
int main(){
  int data1[R*C]={ 1, 2,
                   3, 4
                 };
  int data2[R*C]={ 3, 5,
                   7, 8};
  
  int result[R*C]={0 };
  int r,c;
  for(r=0; r< R ; r++){
     for(c=0; c< C ; c++){
      result[r*C + c]= data1[r*C + c]  + data2[r*C + c];
     }
  }
  printf("\n MAtrix SUM\n");
  for(r=0; r< R ; r++){
     for(c=0; c< C ; c++){
      printf("%-3d ",result[r*C + c]);
    }
    printf("\n");
  }
  return 1;
}


Output:
1
2
3
4

 MAtrix SUM
4   7   
10  12  


Create a new paste based on this one


Comments: