Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

From four different numbers, how can I find out the minimum and maximum numbers that can created from the digits?

Asked by chathura on 11 May 2013

e.g., from 7465 :

The digits = 7, 4, 6, and 5, so:

Minimum = 4567, the maximum = 7654

0 Comments

chathura

Tags

No tags are associated with this question.

Products

No products are associated with this question.

1 Answer

Answer by Iman Ansari on 12 May 2013
Accepted answer

Hi.

A=7465;
A=num2str(A)';
Minimum=str2num(sort(A)')
maximum=str2num(sort(A,'descend')')

3 Comments

chathura on 13 May 2013

if it is necessary, to program counted how many of these steps need to do to get the number 6574, how can I do this with that....

Iman Ansari on 13 May 2013

I don't understand.

Iman Ansari on 13 May 2013
A=7465;
A=num2str(A)';
A_sort=sort(A);
New=str2num([A_sort([3 2 4 1])]')
Iman Ansari

Contact us