Question: Error, (in f) division by zero

How can i solve the problem? (Error, (in f) division by zero)

 

restart;
f := proc (z, n) local x, i, k, j;
for i to n
do
if i = n then x[i] := trunc(z/10^(n-1))
else x[i] := trunc((`mod`(z, 10^i))/10^(i-1))
end if
end do;
printf("The number %d has the digits:", z);
x[n+1] := 0;
for k from n by -1 to 1
do
print(x[k]);
x[n+1] := x[n+1]+x[k]
end do;
printf("The checksum is:");
print(x[n+1]);
for j to n
do
if `mod`(z, x[j]) = 0 then printf("The number is divisible by: %d\n", x[j])
else printf("The number is not divisible by: %d\n", x[j])
end if
end do;
for j to n
do
if `mod`(x[n+1], x[j]) = 0 then printf("The sum is divisible by: %d\n", x[j])
else printf("The sum is not divisible by: %d\n", x[j])
end if
end do
end proc;

f(12305, 4)

Error, (in f) division by zero

Please Wait...