Jump to content

Harshad or Niven series: Difference between revisions

m
(→‎{{header|UNIX Shell}}: Add implementation)
Line 4,810:
{{works with|Korn Shell}}
{{works with|Z Shell}}
<syntaxhighlight lang="bash">function main {
local -i i=0
function main {
gen_harshad | while read n; do
local -i i=0
if (( !i++ )); then
gen_harshad | while read n; do
if (( !i ));printf then'%d' "$n"
elif printf(( '%d'i "$n"< 20 )); then
elif (( i <printf 20' ));%d' then"$n"
elif printf(( 'i %d'== "$n"20 )); then
elif (( i ==printf 20 )); then'\n'
elif (( n > 1000 )); then
printf '\n'
elif (( n >printf 1000'%d\n' )); then"$n"
printf '%d\n' "$n"return
returnfi
fi (( i++ ))
done
(( i++ ))
done
}
 
function is_harshad {
local -i sum=0 n=$1 i
for (( i=0; i<${#n}; ++i )); do
(( sum += ${n:$i:1} ))
done
(( n % sum == 0 ))
}
 
Line 4,851 ⟶ 4,850:
1002
</pre>
 
 
=={{header|VBA}}==
1,481

edits

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