MATLAB: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Write a function called smallest_multiple that returns a uint64, the smallest positive number that is evenly divisible by all of the numbers

helphomeworkMATLABproblem foursmallest_multiple

I keep getting an error everytime I run my code that says:
[out] = smallest_multiple(6)
Error using gcd (line 23)
Inputs must be floats, namely single or double.
Error in smallest_multiple (line 4)
out = (out * i) / (gcd(out,i));
Is 6 not a single?
Here is my code:
function [out] = smallest_multiple(n)
out = uint64(1);
for i = 1 : n
out = (out * i) / (gcd(out,i));
end
if out >= intmax('uint64')
out = uint64(0);
end
end

Best Answer

Omit the explicit casting by uint64. Then Matlab uses the type double as default.