fork download
  1. //第4回 課題2
  2.  
  3. #include <stdio.h>
  4.  
  5. void array_mul(int (*x)[2],int (*y)[2],int (*ans)[2]);
  6.  
  7. int main(void){
  8. int x[2][2]={
  9. {1, 2},
  10. {3, 4}
  11. };
  12. int y[2][2]={
  13. {1, 2},
  14. {3, 4}
  15. };
  16. int ans[2][2];
  17.  
  18. array_mul(x, y, ans);
  19.  
  20. for(int i=0;i<2;i++){
  21. for (int j=0;j<2;j++){
  22. printf("%4d", ans[i][j]);
  23. }
  24. printf("\n");
  25. }
  26.  
  27. return 0;
  28. }
  29.  
  30. void array_mul(int (*x)[2],int (*y)[2],int (*ans)[2]){
  31. for (int i=0;i<2;i++){
  32. for (int j=0;j<2;j++){
  33. ans[i][j]=0;
  34. for (int k=0;k<2;k++) {
  35. ans[i][j]+=x[i][k]*y[k][j];
  36. }
  37. }
  38. }
  39. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
   7  10
  15  22