Matrices in PSeInt: two-dimensional arrays
3 examples
How it works
A matrix is a two-dimensional array: a table with rows and columns. You create it with Dimension ventas[3, 5] (3 rows, 5 columns) and name each cell with two indexes, ventas[row, column].
To walk it you use two Para loops, one inside the other: the outer one moves through the rows and the inner one through that row's columns. That's how you fill it, print it as a table or add it up by row and by column.
Matrices are used for game boards, several students' grades in several subjects, or sales per day and per branch.
Short example
The least you need to see it work. Copy it or open it in the editor.
Algoritmo SumTable Definir f, c Como Entero Dimension tabla[3, 4] Para f <- 1 Hasta 3 Hacer Para c <- 1 Hasta 4 Hacer tabla[f, c] <- f + c Escribir Sin Saltar tabla[f, c], " " FinPara Escribir "" FinParaFinAlgoritmoWhat it prints:
2 3 4 5 3 4 5 6 4 5 6 7
Opens in the browser editor, nothing to install.
Solved exercises
Each exercise comes with the full code, its flowchart and a sample run.
Weekly Sales
A table of sales by branch and day, with totals.
AdvancedTic-Tac-Toe
The classic three-in-a-row game for two players.
AdvancedClass Grade Book
Records three grades per student and builds a class report.
Advanced
In the language reference
The instructions involved, explained one by one.
Other concepts
Codoritmo is an independent, open-source project inspired by PSeInt and compatible with its syntax. It is not affiliated with the PSeInt project. Official PSeInt website.