# transpose a matrix
resource trans5()
	const int W = 5
	int  a[1:10,1:10] 
	op init()
	op print()
	op transpose()

	init()
	print()
	transpose()
	print()

	proc init()  {
		int  count = 0

		for [ r = 1 to 10 ] {
			for [ c = 1 to 10 ] {
				count ++
				a[r,c] = count
			}
		}
	}
	# handles only positive numbers of size with at most W digits.
	op itoa(int x) returns char s[1:W]
	proc itoa(x) returns s  {
		for [ p = 1 to W ] { s[p] = ' ' }
		if (x == 0) {
			s[W] = '0'
		} else {
			int  p = W
			while (x != 0 & p > 0) {
				s[p] = char(48+x%10)
				x = x/10; p--
			}
		}
	}

	proc print()  {
		write("----",10)
		for [ r = 1 to 10 ] {
			for [ c = 1 to 10 ] {
				put (" "); put( itoa( a[r,c] ) )
			}
			write()
		}
	}
	proc transpose()  {
		if (10 == 10) {
		    for [ r = 1 to 10 ] {
			    for [ c = 1 to r-1 ] {
				    a[r,c] :=: a[c,r]
			    }
		    }
		} else {
			write("major booboo")
		}
	}
end
