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

New to MATLAB?

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

Asked by chathura

chathura (view profile)

on 11 May 2013

e.g., from 7465 :

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

Minimum = 4567, the maximum = 7654

0 Comments

chathura

chathura (view profile)

Tags

No tags are associated with this question.

Products

No products are associated with this question.

1 Answer

Answer by Iman Ansari

Iman Ansari (view profile)

on 12 May 2013
Accepted answer

Hi.

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

3 Comments

chathura

chathura (view profile)

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

Iman Ansari (view profile)

on 13 May 2013

I don't understand.

Iman Ansari

Iman Ansari (view profile)

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

Iman Ansari (view profile)

Contact us