How to print number in a diamond shape
How to print number in a diamond shape?
Write a program using the for loop to get the output like:
1<br/>
1 2 1<br/>
1 2 3 2 1<BR/>
1 2 3 4 3 2 1<BR/>
1 2 3 4 5 4 3 2 1<BR/>
Abstract
:
By using for and while loop we will get the diamond shape.Take the below code
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim i As Integer
For i = 1 To 5
If i = 1 Then
'Here i will print 1
Response.Write(i)
Response.Write("")
Else
Dim j, k As Integer
For j = 1 To i
'Here we will print
'1
'12
'123
'1234
'12345
Response.Write(j)
Next
k = i
Dim count As Integer
count = j - 1
While k <= i
If k = 0 Then
Exit While
End If
If k <> count Then
'Here we will print
'2
'21
'321
'4321
Response.Write(k)
End If
k = k - 1
End While
Response.Write("")
End If
Next
End If
End Sub
End Class
THANKS :)