matlab:怎样编写找出所有由1-9九个数字组成的式子,满足:一个三位数减去另一个三位数等于另一个三位数
1个回答

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=%dn',num1,num2,num3);end

end

end