The integer 145 has the curious property that 145 = 1! + 4! + 5!It is possible to prove mathematically that there is no integer greater than 200,000 with this property. There is only one whole number (integer) other than 1, 2, and 145 which has this property. Write a function, curious_property, which finds this number
MATLAB Script:
close all
clear
clc
curious_property()
function curious_property()
fprintf('Numbers with Curious Property:\n')
for i = 1:200000
list = []; % List for storing each digit of a number
x = i;
while true
list = [list, rem(x,10)]; % Keep storing the remainders (individual
digits of a number)
if x < 10
break
end
x = floor(x/10);
end
if sum(factorial(list)) == i % Curious property
fprintf('\t%d\n', i)
end
end
end
Output:
Numbers with Curious Property:
1
2
145
40585
Get Answers For Free
Most questions answered within 1 hours.