假设我们已经为因式分解下面的脚本格式因式分解算法的
z=input('enter your number : ');
for ii=2:z
s=0;
while z/ii==floor(z/ii) % check if z is divisible by ii
z=z/ii;
s=s+1;
end
if s>0
str = [num2str(ii) '^' num2str(s) ];
disp(str) ;
% If z = 1, no more divisions are necessary,
% thus breaks the loop and quits
if z == 1
break
end
end
end
但是这个代码的输出未格式化好,例如
>> integer_factorization
enter your number : 30
2^1
3^1
5^1
我怎么可以这样做,我得到了
30=2^1*3^1*5^1?
在此先感谢
请检查我的答案,它完美的工作。 – ABcDexter