Jump to content

Roman numerals/Encode: Difference between revisions

Roman numerals/Encode in Gambas
(Roman numerals/Encode in Gambas)
Line 1,422:
33 = XXXIII
</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
'Testing
Print "2009 = "; toRoman(2009)
Print "1666 = "; toRoman(1666)
Print "3888 = "; toRoman(3888)
 
End
 
Function toRoman(value As Integer) As String
 
Dim result As String
Dim arabic As Integer[] = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
Dim roman As String[] = ["M", "CM", "D", "CD", "C", "XC", "L" , "XL", "X", "IX", "V", "IV", "I"]
 
For i As Integer = 0 To arabic.Max
Do While value >= arabic[i]
result &= roman[i]
value -= arabic[i]
Loop
Next
Return result
 
End Function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=== {{header|GW-BASIC}} ===
2,122

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.