50 lines
1.3 KiB
Nim
50 lines
1.3 KiB
Nim
import strutils, sequtils, os, procedures #, strformat
|
|
|
|
var operation: string
|
|
case paramStr(0):
|
|
of "dot":
|
|
operation = "dot"
|
|
echo "Parameter is dot"
|
|
of "cross":
|
|
operation = "cross"
|
|
echo "Parameter is cross"
|
|
else:
|
|
# TODO: ask user to preform dot or cross product
|
|
echo "maultrix"
|
|
|
|
|
|
echo "Enter number of rows in the first matrix:"
|
|
let r1: int = parseInt(readLine(stdin))
|
|
echo "Enter number of columns in the first matrix:"
|
|
let c1: int = parseInt(readLine(stdin))
|
|
var m1 = newSeqWith(r1, newSeq[float](c1))
|
|
|
|
procedures.fillMatrix(m1, r1, c1)
|
|
|
|
echo ""
|
|
|
|
echo "Enter number of rows in the second matrix:"
|
|
let r2: int = parseInt(readLine(stdin))
|
|
echo "Enter number of columns in the second matrix:"
|
|
let c2: int = parseInt(readLine(stdin))
|
|
var m2 = newSeqWith(r2, newSeq[float](c2))
|
|
|
|
procedures.fillMatrix(m2, r2, c2)
|
|
|
|
var m = newSeqWith(0, newSeq[float](0)) # ? double check this
|
|
|
|
# TODO: calculate dot product (in procedures)
|
|
for i in countup(1, r1):
|
|
for j in countup(1, c1):
|
|
m[i-1].add( m1[i-1][j-1] * m2[j-1][i-1] + m1[i][j] * m2[j][i] ) # ? double check this
|
|
m[i-1].delete(0)
|
|
|
|
# TODO: calculate cross product (in procedures)
|
|
|
|
echo "\nFirst matrix is:"
|
|
procedures.printMatrix(m1, r1)
|
|
echo "\nSecond matrix is:"
|
|
procedures.printMatrix(m2, r2)
|
|
|
|
# TODO: print result to stdout
|
|
procedures.printMatrix(m, r1) |