Problem 16 : Power digit sum
= 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number ?
思路 :
这题就是一个数据的处理,将数字转换成字符串,然后循环加和!
代码 :
clc;clear;
tic
sum = 0;
A = char(sym(2^1000))
B = length(A);
for i = 1:B
sum = sum + str2num(A(i));
end
fprintf('Result = %.0d\n',sum);
toc