Jumat, 26 November 2010

Fungsi Terbilang Console Application


Module Module1

Public Function Terbilang(ByVal x As Integer) As String

 Dim bilangan As String() = {"", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas"}

        Dim temp As String = ""

        If x < 12 Then

            temp = bilangan(x)

        ElseIf x < 20 Then

            temp = Terbilang(x - 10) + " belas "

        ElseIf x < 100 Then

            temp = Terbilang(x / 10) + " puluh " + Terbilang(x Mod 10)

        ElseIf x < 200 Then

            temp = " seratus" + Terbilang(x - 100)

        ElseIf x < 1000 Then

            temp = Terbilang(x / 100) + " ratus " + Terbilang(x Mod 100)

        ElseIf x < 2000 Then

            temp = " seribu " + Terbilang(x - 1000)

        ElseIf x < 1000000 Then

            temp = Terbilang(x / 1000) + " ribu " + Terbilang(x Mod 1000)

        ElseIf x < 1000000000 Then

            temp = Terbilang(x / 1000000) + " juta " + Terbilang(x Mod 1000000)

        End If

        Return temp

    End Function

    Sub main()
        Dim bilang As String
        Dim nilai As Long

        Console.Write("Masukan bilangan : ")
        nilai = Console.ReadLine
        bilang = Terbilang(nilai)
        Console.Write(bilang)
        Console.ReadKey()

    End Sub

End Module

Tidak ada komentar:

Posting Komentar