MATLAB 水仙花数程序:寻找所有三位水仙花数
以下是使用MATLAB编写的程序,用于找出所有的水仙花数:\n\nMATLAB\nfor num = 100:999\n digit1 = floor(num/100); \x25 % 百位数字\n digit2 = floor(mod(num, 100)/10); \x25 % 十位数字\n digit3 = mod(num, 10); \x25 % 个位数字\n \n if num == digit1^3 + digit2^3 + digit3^3\n disp(num);\n end\nend\n\n\n运行这段程序,将输出所有的水仙花数:\n\n\n153\n370\n371\n407\n
原文地址: https://www.cveoy.top/t/topic/pKnb 著作权归作者所有。请勿转载和采集!