Monday, September 21, 2015

PRINT STAR PATTERN IN VB.NET USING NESTED FOR LOOP


Above pattern print program is given below -

 Dim row, col, col1, col2, noofrow, noofcol, colspace As Integer
        noofrow = 15 : noofcol = noofrow : colspace = 0
        For row = 1 To noofrow
            For col = 1 To noofcol
                Console.Write("*")
            Next
            For col1 = 1 To colspace
                Console.Write(" ")
            Next
            For col2 = 1 To noofcol
                Console.Write("*")
            Next
            Console.Write(vbNewLine)
            noofcol -= 1
            colspace += 2
        Next

        Dim row1, co3, col4, col5, noofrow1, noofcol1, colspace1 As Integer
        noofrow1 = 15 : noofcol1 = noofrow1 : colspace1 = (noofrow1 * 2) - 2
        For row1 = 1 To noofrow
            For co3 = 1 To row1
                Console.Write("*")
            Next
            For col4 = 1 To colspace1
                Console.Write(" ")
            Next
            For col5 = 1 To row1
                Console.Write("*")
            Next
            Console.Write(vbNewLine)
            colspace1 -= 2
        Next

0 comments:

Post a Comment