以下是使用MATLAB编写的代码,用于计算并输出所有的水仙花数:\n\nmatlab\nfor num = 100:999\n units = rem(num, 10);\n tens = rem(floor(num/10), 10);\n hundreds = floor(num/100);\n \n if (units^3 + tens^3 + hundreds^3) == num\n disp(num);\n end\nend\n\n\n运行上述代码,将输出所有的水仙花数:\n\n\n153\n370\n371\n407\n

MATLAB代码实现:寻找水仙花数

原文地址: https://www.cveoy.top/t/topic/pKly 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录