Finding Digits of a Number
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Given any number, find all the digits of the
number;
For example: 456
-
Digits are 4, 5, 6
WITH LOOPS
0 commentaires
Réponses (1)
Asmit Singh
le 1 Juin 2021
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 commentaires
Voir également
Catégories
En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!