> 其他 >
matlab:怎样编写找出所有由1-9九个数字组成的式子,满足:一个三位数减去另一个三位数等于另一个三位数
人气:485 ℃ 时间:2019-09-02 09:40:34
解答
for num1=100:999
for num2=100:999
num3=num1-num2;
if(num3999),continue;end
temp=strcat(num2str(num1),num2str(num2),num2str(num3));
flag=1;
for cnt1=1:length(temp)-1
for cnt2=cnt1+1:length(temp)
if(any(temp=='0',2)),flag=0;break,end
if(temp(cnt1)==temp(cnt2)),flag=0;break,end
end
if(flag==0),break,end
end
if(flag==1),fprintf('%d-%d=%d\n',num1,num2,num3);end
end
end
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版