MATLAB: Need solution asap for the hw about summing each character in student number that we input the data

MATLABsum

num=input('enter your student number here : ');
number is 20758562
how can i sum each number ?

Best Answer

num = input('enter your student number here : ');
NumChar = num2str (num);
MySum = 0;
for i1 = 1:numel (NumChar)
MySum = MySum + str2double (NumChar(i1));
end
fprintf ('Sum of the numbers is %d', MySum);
Related Question