Inconsummate numbers in base 10: Difference between revisions
Content added Content deleted
(added RPL) |
(Added various BASIC dialects (BASIC256, Chipmunk Basic, GW-BASIC, QBasic, True Basic, QBasic, True BASIC, XBasic and Yabasic)) |
||
Line 358: | Line 358: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
{{works with|QBasic}} |
|||
<syntaxhighlight lang="basic">10 DEFINT A-Z |
<syntaxhighlight lang="basic">10 DEFINT A-Z |
||
20 M=999 |
20 M=999 |
||
Line 383: | Line 384: | ||
491 492 493 494 497 |
491 492 493 494 497 |
||
498 516 521 522 527</pre> |
498 516 521 522 527</pre> |
||
==={{header|BASIC256}}=== |
|||
{{trans|BASIC}} |
|||
<syntaxhighlight lang="qbasic">m = 999 |
|||
dim c(m) fill false |
|||
z = m * 9 * (length(string(m))-1) |
|||
for i = 10 to z |
|||
j = i |
|||
s = 0 |
|||
while j <> 0 |
|||
s += (j % 10) |
|||
j /= 10 |
|||
end while |
|||
if i % s = 0 then j = i \ s : if j <= m then c[j] = true |
|||
next i |
|||
cont = 0 |
|||
print "The first 50 inconsummate numbers:" |
|||
for i = 10 to m |
|||
if cont = 50 then end |
|||
if not c[i] then cont += 1 : print rjust(string(i), 4); |
|||
next i</syntaxhighlight> |
|||
==={{header|Chipmunk Basic}}=== |
|||
{{trans|BASIC}} |
|||
{{works with|Chipmunk Basic|3.6.4}} |
|||
{{works with|GW-BASIC}} |
|||
{{works with|Just BASIC}} |
|||
{{works with|QBasic}} |
|||
<syntaxhighlight lang="qbasic">110 m = 999 |
|||
120 dim c(m) |
|||
130 z = m*9*(len(str$(m))-1) |
|||
140 for i = 10 to z |
|||
150 j = i : s = 0 |
|||
160 s = s+j mod 10 : j = int(j/10) : if j then goto 160 |
|||
170 if i mod s = 0 then j = int(i/s) : if j <= m then c(j) = -1 |
|||
180 next i |
|||
190 j = 0 |
|||
200 for i = 10 to m |
|||
210 if j = 50 then end |
|||
220 if c(i) <> -1 then j = j+1 : print i, |
|||
230 next i</syntaxhighlight> |
|||
==={{header|GW-BASIC}}=== |
|||
{{works with|PC-BASIC|any}} |
|||
{{works with|BASICA}} |
|||
The [[#Chipmunk Basic|Chipmunk Basic]] solution works without any changes. |
|||
==={{header|QBasic}}=== |
|||
{{works with|QBasic|1.1}} |
|||
{{works with|QuickBasic|4.5}} |
|||
The [[#BASIC|BASIC]] solution works without any changes. |
|||
==={{header|True BASIC}}=== |
|||
{{trans|BASIC}} |
|||
<syntaxhighlight lang="qbasic">LET m = 999 |
|||
DIM c(0) |
|||
MAT REDIM c(m) |
|||
LET z = m * 9 * (LEN(STR$(m))-1) |
|||
FOR i = 10 TO z |
|||
LET j = i |
|||
LET s = 0 |
|||
DO |
|||
LET s = s + REMAINDER(j,10) |
|||
LET j = INT(j/10) |
|||
LOOP WHILE j <> 0 |
|||
IF REMAINDER(i,s) = 0 THEN |
|||
LET j = INT(i/s) |
|||
IF j <= m THEN LET c(j) = -1 |
|||
END IF |
|||
NEXT i |
|||
LET cont = 0 |
|||
PRINT "The first 50 inconsummate numbers:" |
|||
FOR i = 10 TO m |
|||
IF cont = 50 THEN EXIT FOR |
|||
IF c(i) <> -1 THEN |
|||
LET cont = cont + 1 |
|||
PRINT i; |
|||
END IF |
|||
NEXT i |
|||
END</syntaxhighlight> |
|||
==={{header|XBasic}}=== |
|||
{{trans|BASIC256}} |
|||
{{works with|Windows XBasic}} |
|||
<syntaxhighlight lang="qbasic">PROGRAM "Inconsummate numbers in base 10" |
|||
VERSION "0.0000" |
|||
DECLARE FUNCTION Entry () |
|||
FUNCTION Entry () |
|||
m = 999 |
|||
DIM c[m] |
|||
x$ = STRING$(m) |
|||
z = m * 9 * LEN(x$) - 1 |
|||
FOR i = 10 TO z |
|||
j = i |
|||
s = 0 |
|||
DO WHILE j <> 0 |
|||
s = s + (j MOD 10) |
|||
j = INT(j / 10) |
|||
LOOP |
|||
IF i MOD s = 0 THEN |
|||
j = INT(i / s) |
|||
IF j <= m THEN c[j] = $$TRUE |
|||
END IF |
|||
NEXT i |
|||
cont = 0 |
|||
PRINT "The first 50 inconsummate numbers:" |
|||
FOR i = 10 TO m |
|||
IF cont = 50 THEN EXIT FOR |
|||
IF NOT c[i] THEN INC cont : PRINT FORMAT$("####",i); |
|||
NEXT i |
|||
END FUNCTION |
|||
END PROGRAM</syntaxhighlight> |
|||
==={{header|Yabasic}}=== |
|||
{{trans|BASIC}} |
|||
<syntaxhighlight lang="vb">m = 999 |
|||
dim c(m) |
|||
z = m * 9 * (len(str$(m))-1) |
|||
for i = 10 to z |
|||
j = i |
|||
s = 0 |
|||
while j <> 0 |
|||
s = s + mod(j, 10) |
|||
j = int(j / 10) |
|||
wend |
|||
if mod(i, s) = 0 then j = int(i / s) : if j <= m then c(j) = true : fi : fi |
|||
next i |
|||
cont = 0 |
|||
print "The first 50 inconsummate numbers:" |
|||
for i = 10 to m |
|||
if cont = 50 end |
|||
if not c(i) then cont = cont + 1 : print i using("####"); : fi |
|||
next i |
|||
print</syntaxhighlight> |
|||
=={{header|C++}}== |
=={{header|C++}}== |