Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = input('Enter Number n: ');
- sum = 0;
- str = num2str(n);
- for i=1:1:numel(str)
- sum = sum + (str2num(str(i)));
- fprintf('%d\n', str2num(str(i)));
- end
- fprintf('sum = %d\n', sum);
- % Or
- nums = [];
- num = input('enter num: ');
- while num ~= 0
- nums = [nums mod(num, 10)];
- num = fix(num/10);
- end
- nums = nums(numel(nums):-1:1);
- disp(nums);
- disp(sum(nums));
Advertisement
Add Comment
Please, Sign In to add comment