Given any number, find all the digits of the
number;
For example: 456
-
Digits are 4, 5, 6
WITH LOOPS

Antworten (1)

Asmit Singh
Asmit Singh am 1 Jun. 2021

0 Stimmen

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 Kommentare

ceren uçak
ceren uçak am 1 Jun. 2021
Thank you very much for answering the question.
James Tursa
James Tursa am 1 Jun. 2021
@Asmit Singh Please do not post complete answers to homework questions.

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2020b

Gefragt:

am 1 Jun. 2021

Kommentiert:

am 1 Jun. 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by