From eae5c23730bde9d0e43a9e90c0306fbf3b63ba69 Mon Sep 17 00:00:00 2001 From: array-in-a-matrix Date: Thu, 17 Nov 2022 20:44:33 -0500 Subject: [PATCH] kid named finger --- Makefile | 12 ++++++++---- src/main.nim | 32 ++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index ab34682..d18537a 100644 --- a/Makefile +++ b/Makefile @@ -4,16 +4,20 @@ DOC_DIR := doc/ DOC_TYPE ?= doc all: - nim compile --out:$(BUILD_DIR) $(SRC_DIR)*.nim + nim compile --out:$(BUILD_DIR) $(SRC_DIR)*.nim doc: nim $(DOC_TYPE) --outdir:$(DOC_DIR) $(SRC_DIR)*.nim -release: +release: clean nim compile --define:release --out:$(BUILD_DIR) $(SRC_DIR)*.nim -run: - @$(BUILD_DIR)main +run: all + @echo "====================================================" + @echo "" + @$(BUILD_DIR)main + +crun: clean run clean: @rm -rf $(BUILD_DIR) $(DOC_DIR) diff --git a/src/main.nim b/src/main.nim index d452ba9..8e14d1d 100644 --- a/src/main.nim +++ b/src/main.nim @@ -1,12 +1,28 @@ -## This module is a sample. +import strutils, sequtils #, strformat -import strutils +proc print_matrix(matrix: seq[seq[float]], row: int) = + for i in countup(1, row): + echo matrix[i-1] -proc helloWorld*(times: int) = - ## Takes an integer and outputs - ## as many indented "hello world!"s +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] - for i in 0 .. times-1: - echo "hello world!".indent(2) # using indent to avoid `UnusedImport` +echo "Enter number of rows:" +let row: int = parseInt(readLine(stdin)) -helloWorld(5) \ No newline at end of file +echo "Enter number of columns:" +let col: int = parseInt(readLine(stdin)) + +var matrix = newSeqWith(row, newSeq[float](col)) + + +fill_matrix(matrix, row, col) + +echo "\nMatrix entered is:" +print_matrix(matrix, row)