How to resolve the algorithm Zig-zag matrix step by step in the Yabasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Zig-zag matrix step by step in the Yabasic programming language
Table of Contents
Problem Statement
Produce a zig-zag array.
A zig-zag array is a square arrangement of the first N2 natural numbers, where the
numbers increase sequentially as you zig-zag along the array's anti-diagonals.
For a graphical representation, see JPG zigzag (JPG uses such arrays to encode images).
For example, given 5, produce this array:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Zig-zag matrix step by step in the Yabasic programming language
Source code in the yabasic programming language
Size = 5
DIM array(Size-1, Size-1)
i = 1
j = 1
FOR e = 0 TO Size^2-1
array(i-1, j-1) = e
IF and((i + j), 1) = 0 THEN
IF j < Size then j = j + 1 ELSE i = i + 2 end if
IF i > 1 i = i - 1
ELSE
IF i < Size then i = i + 1 ELSE j = j + 2 end if
IF j > 1 j = j - 1
ENDIF
NEXT e
FOR row = 0 TO Size-1
FOR col = 0 TO Size-1
PRINT array(row,col) USING "##";
NEXT col
PRINT
NEXT row
You may also check:How to resolve the algorithm Fusc sequence step by step in the RPL programming language
You may also check:How to resolve the algorithm Dot product step by step in the Prolog programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Frink programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Babbage problem step by step in the FutureBasic programming language