fork download
  1. #include <stdio.h>
  2.  
  3. #define M 2 // 行数
  4. #define N 3 // 列数
  5.  
  6. void add(int *A, int *B, int *C, int m, int n)
  7. {
  8. int i,j;
  9. for(i=0;i<m;i++)
  10. {
  11. for(j=0;j<n;j++)
  12. {
  13. C[i*n+j]=A[i*n+j]+B[i*n+j];
  14. printf("%3d",C[i*n+j]);
  15. }
  16. printf("\n");
  17. }
  18. }
  19.  
  20.  
  21. int main(void)
  22. {
  23. int A[][N] = {{1,2,3},{4,5,6}};
  24. int B[][N] = {{6,5,4},{3,2,1}};
  25. int C[][N] = {{0,0,0},{0,0,0}};
  26.  
  27. add(A,B,C,2,3);
  28.  
  29. // your code goes here
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
  7  7  7
  7  7  7