Jump to content

Sum digits of an integer: Difference between revisions

Added MSX Basic
(Added Gambas)
(Added MSX Basic)
Line 986:
110 END
</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
<syntaxhighlight lang="qbasic">10 CLS
20 PRINT "The sums of the digits are:" : PRINT
30 B = 10
40 N$ = "1" : GOSUB 100 : PRINT "1 base 10 :" N
50 N$ = "1234" : GOSUB 100 : PRINT "1234 base 10 :" N
60 B = 16
70 N$ = "FE" : GOSUB 100 : PRINT "FE base 16 :" N
80 N$ = "F0E" : GOSUB 100 : PRINT "F0E base 16 :" N
90 END
100 REM SUM DIGITS OF N$, B
110 IF B = 1 THEN N = LEN(N$) : RETURN
120 IF B < 2 THEN B = 10
130 N = 0
140 V$ = LEFT$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", B)
150 FOR I = 1 TO LEN(N$)
160 C$ = MID$(N$, I, 1)
170 FOR J = 1 TO LEN(V$)
180 IF C$ <> MID$(V$, J, 1) THEN NEXT J : N = SQR(-1) : STOP
190 N = N + J - 1
200 NEXT I
210 RETURN</syntaxhighlight>
{{out}}
<pre>Similar to FreeBASIC entry.</pre>
 
==={{header|Palo Alto Tiny BASIC}}===
2,130

edits

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