对自己很是无语!
function D = strAdd(str1)
n1 = length(str1);
n2 = length(str2);
flag = 0;
D = [];
while n1 >= 1 & n2 >= 1
a = str2double(str1(n1));
b = str2double(str2(n2));
c = mod(a + b + flag,10);
flag = floor((a + b + flag) / 10);
D = [D,c];
n1 = n1 - 1;
n2 = n2 - 1;
end
while n1 >= 1
a = str2double(str1(n1));
c = mod(a + flag,10);
flag = floor((a + flag) / 10);
D = [D,c];
n1 = n1 - 1;
end
while n2 >= 1
a = str2double(str2(n2));
c = mod(a + flag,10);
flag = floor((a + flag) / 10);
D = [D,c];
n2 = n2 - 1;
end
if flag > 0
D = [D,flag];
end
D = D(end : -1 :1);
end
本文深入探讨了一种独特的函数实现方法,旨在解决字符串加法问题。通过详细解析过程,揭示了字符串转换为数值进行加法运算的技巧,并最终将结果转换回字符串形式,提供了一个有趣且实用的编程解决方案。

1538

被折叠的 条评论
为什么被折叠?



