Increasing gaps between consecutive Niven numbers: Difference between revisions

Increasing gaps between consecutive Niven numbers en BASIC256
(Increasing gaps between consecutive Niven numbers en Yabasic)
(Increasing gaps between consecutive Niven numbers en BASIC256)
Line 98:
22 108 3750017 49989744
</pre>
 
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<lang BASIC256>
function digit_sum(n, sum)
# devuelve la suma de los dígitos de n dada la suma de los dígitos de n - 1
sum ++
while (n > 0 and n mod 10 = 0)
sum -= 9
n = int(n / 10)
end while
return sum
end function
 
function divisible(n, d)
if ((d mod 1) = 0) and ((n mod 1) = 1) then
return 0
end if
return (n mod d = 0)
end function
 
global sum
sum = 0
gap = 0 : niven = 0 : niven_index = 0
gap_index = 0
previous = 1
print "Gap index Gap Niven index Niven number"
print "--------- --- ----------- ------------"
 
for niven = 1 to 1000000
sum = digit_sum(niven, sum)
if divisible(niven, sum) then
if (niven > previous + gap) then
gap_index += 1
gap = niven - previous
print gap_index, gap, niven_index, previous
end if
previous = niven
niven_index ++
end if
next niven
end
</lang>
 
 
=={{header|C}}==
{{trans|C++}}
2,142

edits