Wednesday, October 19, 2011

Circular matrix in vb.net

Dim c As Integer = 1
Dim i, j, k, n, x As Integer
Dim m As Integer = 0

n = 5
x = n

Dim a(n, n) As Integer

While n >= 1
For k = 0 To n - 1
a(m, k + m) = c
c = c + 1
Next

For k = 1 To n - 1
a(k + m, n - 1 + m) = c
c = c + 1
Next

For k = n - 2 To 0 Step -1
a(n - 1 + m, k + m) = c
c = c + 1
Next


For k = n - 2 To 1 Step -1
a(k + m, m) = c
c = c + 1
Next

n = n - 2
m = m + 1

End While

Dim strB As New StringBuilder

strB.Append("<table border='1'>")
For i = 0 To x - 1
strB.Append("<tr>")
For j = 0 To x - 1
strB.Append("<td>")
strB.Append(a(i, j))
strB.Append("</td>")
Next
strB.Append("</tr>")
Next
strB.Append("</table>")

Response.Write(strB)

No comments: