Finding Digits of a Number
2 次查看(过去 30 天)
显示 更早的评论
Given any number, find all the digits of the
number;
For example: 456
-
Digits are 4, 5, 6
WITH LOOPS
0 个评论
回答(1 个)
Asmit Singh
2021-6-1
This code basically keeps dividing the number by 10, and uses the remainder as the digit, while the quotient as the new number.
number = 456;
digits = [];
while(number~=0)
remain = rem(number,10);
number = fix(number/10);
digits=[digits remain];
end
digits = fliplr(digits)
2 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!