加了简单的注释,无误后改输出为R.txt。- @echo off&setlocal enabledelayedexpansion
-
- rem ------------------------------
- rem 创建两个矩阵
- rem ------------------------------
-
- call :create a.txt A
- call :create b.txt B
-
- rem -----------------------------
- rem 验证是否可以进行矩阵乘法
- rem -----------------------------
-
- if not !lie_A! equ !hang_B! (
- echo 两矩阵无法相乘
- pause>nul
- goto :eof
- )
-
- rem ------------------------------
- rem 矩阵相乘
- rem ------------------------------
-
- echo.&echo The result is:&echo.
- set /a hang_A-=1,lie_B-=1,lie_A-=1
- for /l %%i in (0 1 !hang_A!) do (
- for /l %%j in (0 1 !lie_B!) do (
- for /l %%k in (0 1 !lie_A!) do (
- set /a tmp=.A%%i%%k*.B%%k%%j
- set /a result+=tmp
- )
- call :unify
- set /p= !result!<nul
- set /a result=0
- )
- echo.
- )
- pause>nul
- goto :eof
-
- rem ----------------------------
- rem 子程序:创建矩阵
- rem ----------------------------
-
- :create
- set /a i=0
- for /f "delims=" %%a in (%~1) do (
- set /a j=0
- set "str=%%a"
- for %%b in (!str!) do (
- set .%~2!i!!j!=%%b
- set /a j+=1
- )
- set /a i+=1
- )
- set /a hang_%~2=i,lie_%~2=j
- goto :eof
-
- rem -----------------------------
- rem 子程序:统一输出格式
- rem -----------------------------
-
- :unify
- if !result! lss 100 set "result= !result!"
- if !result! lss 10 set "result= !result!"
- goto :eof
复制代码
|