fork download
  1. /*
  2. 行列xを表示
  3. 1 2
  4. 3 4
  5. 5 6
  6.  
  7. 行列yを表示
  8. 1 2 4
  9. 3 6 9
  10.  
  11. 行列xとyの積を表示
  12.  */
  13. /* 計算する行列 */
  14. #define MATRIXA {{1,2},{3,4},{5,6}} /* 行列A */
  15. #define MATRIXA_X 3 /* 行列Aの大きさ */
  16. #define MATRIXA_Y 2 /* 行列Aの大きさ */
  17. #define MATRIXB {{1,2,4},{3,6,9}} /* 行列A */
  18. #define MATRIXB_X 2 /* 行列Bの大きさ */
  19. #define MATRIXB_Y 3 /* 行列Bの大きさ */
  20. /*-- 以上定数 --*/
  21.  
  22.  
  23. /* 以下ソース */
  24. # define s float
  25. #define i int
  26. # define XX \
  27. void X
  28. # define PF "%f"
  29. # define a MATRIXA
  30. # define ic(o) \
  31. ++o
  32. ;
  33. # define a1 MATRIXA_X
  34. # define C char
  35. # define a2 MATRIXA_Y
  36. C t2[]= {0xe8,
  37. 0xa1,0x8c,0xe5,0x88,0x97,0x79,0xe3,0x82,0x92,
  38. 0xe8,0xa1,0xa8,0xe7,0xa4,0xba,0x0};
  39. # define p(o) f("%s\n",o)
  40. # define b1 MATRIXB_X
  41. #define S sizeof
  42. # define z 0
  43. # define f __builtin_printf
  44. # define b MATRIXB
  45. # define b2 MATRIXB_Y
  46. # define sz (4*la*lb)
  47. #define SP " "
  48. #define EY p(e)
  49. #define M main
  50. C t1[]= {0xe8,0xa1,0x8c,0xe5,
  51. 0x88,0x97,0x78,0xe3,0x82,0x92,0xe8,0xa1,0xa8,0xe7,0xa4,0xba,0x0};
  52. #define B ()
  53. #define E X B, 0;
  54. # define l(a) S(a)/S(a[0])
  55. # define al __builtin_alloca \
  56.  
  57. #define zr(o,c) \
  58. __builtin_memset(o,z,c)
  59. # define r for
  60. #define e \
  61. ""
  62. #define op PF SP
  63. C t3[]= {0xe8,0xa1,0x8c,0xe5,0x88,0x97,0x78,0xe3,0x81,0xa8,0x79,0xe3,0x81,0xae,0xe7,0xa9,0x8d,0xe3,0x82,0x92,0xe8,0xa1,0xa8,0xe7,0xa4,0xba,0x0};
  64. XX B{
  65. s ma[a1][a2]=a, mb[b1][b2]=b;
  66. i la=l(ma),la2=l(ma[z]);i lb=l(mb[z]),n=z,x,y,Z;
  67. s*o=al(sz);zr(o,sz);
  68. i lb2=l(mb);
  69. r(Z=z;Z<la;ic(Z)){r(y=z;y<lb;
  70. ic(y)){r(x=z;x<
  71. la2;ic(x)){o[n]+=ma[Z][x]*mb[x][y];
  72. }ic(n);}}
  73. p(t1);r(x=z;x<la;ic(x)){r(y=z;y<la2;ic(y)){
  74. f(op,ma[x][y]);}
  75. p(e);}EY;p(t2);r
  76. (x=z;x<lb2;ic(x)){r(
  77. y=z;y<lb;ic(y)){f(op,mb[x][y]);}
  78. p(e);}EY;p(t3);
  79. r(n=z,y=z;y<lb;ic(y)){r(x=z;x<la;ic(x)){
  80. f(op,o[n++]);}
  81. p(e);}}i M B{return
  82. E}
  83.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
行列xを表示
1.000000 2.000000 
3.000000 4.000000 
5.000000 6.000000 

行列yを表示
1.000000 2.000000 4.000000 
3.000000 6.000000 9.000000 

行列xとyの積を表示
7.000000 14.000000 22.000000 
15.000000 30.000000 48.000000 
23.000000 46.000000 74.000000