move proc to seperate file

This commit is contained in:
array-in-a-matrix 2022-11-17 21:35:45 -05:00
parent 1ef281d891
commit d42bcf9c42
2 changed files with 34 additions and 22 deletions

View file

@ -1,28 +1,24 @@
import strutils, sequtils #, strformat
import strutils, sequtils, procedures #, strformat
proc print_matrix(matrix: seq[seq[float]], row: int) =
for i in countup(1, row):
echo matrix[i-1]
# TODO: check if command was either dot or cross product
proc fill_matrix(matrix: var seq[seq[float]], row, col: int) =
for i in countup(1, row):
for j in countup(1, col):
echo "Enter item in row:"
var entry: float = parseFloat(readLine(stdin))
matrix[i-1].add(entry)
matrix[i-1].delete(0)
echo matrix[i-1]
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))
echo "Enter number of rows:"
let row: int = parseInt(readLine(stdin))
procedures.fillMatrix(m1, r1, c1)
echo "Enter number of columns:"
let col: int = parseInt(readLine(stdin))
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))
var matrix = newSeqWith(row, newSeq[float](col))
procedures.fillMatrix(m2, r2, c2)
fill_matrix(matrix, row, col)
echo "\nMatrix entered is:"
print_matrix(matrix, row)
echo "\nFirst matrix is:"
procedures.printMatrix(m1, r1)
echo "\nSecond matrix is:"
procedures.printMatrix(m2, r2)

16
src/procedures.nim Normal file
View file

@ -0,0 +1,16 @@
import strutils
## prints a matrix to the standard output
proc printMatrix*(matrix: seq[seq[float]], row: int) =
for i in countup(1, row):
echo matrix[i-1]
## get elements of matrix from standard input
proc fillMatrix*(matrix: var seq[seq[float]], row, col: int) =
for i in countup(1, row):
for j in countup(1, col):
echo "Enter item in row:"
var entry: float = parseFloat(readLine(stdin))
matrix[i-1].add(entry)
matrix[i-1].delete(0)
echo matrix[i-1]