Print out all the daffodil numbers. "Daffodil number" refers to a three-digit number, and the sum of the cubes of the ones digit is equal to the number itself.
array = []
for i = 100:999
a = fix(i /100);
b = rem(fix(i / 10), 10);
c = rem(i, 10);
if 100 * a + 10 * b + c == a^3 + b^3 + c^3
array = [array, i]
end
end
array % 打印数组中保存的水仙花数
For taking out three digits
a = fix(i /100);
b = rem(fix(i / 10), 10);
c = rem(i, 10);
It can also be written as follows:
a = floor(i / 100)
c = rem(i, 10)
b = (i - a * 100 - c) / 10