求下一个阿姆斯特朗数 matlab阿姆斯特朗数就是各位数字立方和等于其本身,用matlab实现,我的代码如下:function c = AmsNum_cxd(n)c=n;b = panduan(c);while(b==0)c= c+1;b = panduan(c);endfunction b = panduan(n)sum = 0;t =

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/14 21:11:26
求下一个阿姆斯特朗数 matlab阿姆斯特朗数就是各位数字立方和等于其本身,用matlab实现,我的代码如下:function c = AmsNum_cxd(n)c=n;b = panduan(c);while(b==0)c= c+1;b = panduan(c);endfunction b = panduan(n)sum = 0;t =

求下一个阿姆斯特朗数 matlab阿姆斯特朗数就是各位数字立方和等于其本身,用matlab实现,我的代码如下:function c = AmsNum_cxd(n)c=n;b = panduan(c);while(b==0)c= c+1;b = panduan(c);endfunction b = panduan(n)sum = 0;t =
求下一个阿姆斯特朗数 matlab
阿姆斯特朗数就是各位数字立方和等于其本身,用matlab实现,我的代码如下:
function c = AmsNum_cxd(n)
c=n;
b = panduan(c);
while(b==0)
c= c+1;
b = panduan(c);
end
function b = panduan(n)
sum = 0;
t = (ceil(log10(n))-1);
for i = 1:t
sum = sum + ((mod (n,10^i)-mod(n,10^(i-1)))/10^(i-1))^3;
end
if (sum == n)
b=1;
else b= 0 ;
end
但是有问题,我也是不知道哪里错了,就是调用的时候不出现结果

求下一个阿姆斯特朗数 matlab阿姆斯特朗数就是各位数字立方和等于其本身,用matlab实现,我的代码如下:function c = AmsNum_cxd(n)c=n;b = panduan(c);while(b==0)c= c+1;b = panduan(c);endfunction b = panduan(n)sum = 0;t =

应该是

t = ceil(log10(n));

你的程序可以简洁些:

function c = AmsNum_cxd(n)
while 1
    s = sprintf('%d', n)-'0';
    if sum(s.^3) == n
        c = n;
        return;
    end
    n = n+1;
end
end