본문 바로가기

프로그래밍/알고리즘

[비주얼베이직|초급] 별찍기 변형

반응형

목표는 이거.

     *
    ***
   *****
  *******
 *********

이렇게 나오는 소스는 이거. 변수명을 한글로 썼다. 변수명을 보면 어떤 의도인지 알 수 있을 것이다.

Module Module1

    Sub Main()
        Dim 줄수 As Integer
        Dim 칸수 As Integer
        Dim 줄수최대값 As Integer
        Dim 갯수 As Integer

        줄수최대값 = 5

        For 줄수 = 1 To 줄수최대값

            Dim 빈칸수 As Integer
            빈칸수 = 줄수최대값 - 줄수 + 1

            For 칸수 = 1 To 빈칸수
                Console.Write(" ")
            Next

            Dim 별갯수 As Integer
            별갯수 = 2 * 줄수 - 1

            For 갯수 = 1 To 별갯수
                Console.Write("*")
            Next

            Console.WriteLine()
        Next
        Console.ReadLine()
    End Sub

End Module
728x90