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

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]