make different numbers with the same digits

조회 수: 4 (최근 30일)
Jens Petit-jean
Jens Petit-jean 2020년 10월 19일
댓글: Jens Petit-jean 2020년 10월 19일
I have to ask the user for a positive integer ( input=('give a positive integer') and then ask him through a menu if he wants to make a bigger or smaller number with the same digits so Matlab will calculates the requested number.
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2020년 10월 19일
What if use input 999? Also, if you just want a bigger number, you can add 1.
Jens Petit-jean
Jens Petit-jean 2020년 10월 19일
yeah I know I think 999 just keeps the samen. No I can't just add 1 I need to make the number bigger or smaller just by changing the position of the digits.

댓글을 달려면 로그인하십시오.

답변 (2개)

Vladimir Sovkov
Vladimir Sovkov 2020년 10월 19일
x=1342;
y=str2num(sort(num2str(x),'ascend')); % smaller
z=str2num(sort(num2str(x),'descend')); % bigger

KSSV
KSSV 2020년 10월 19일
str = '215' ;
num = str2num(perms(str)) ;
greater = num(num>str2num(str))
lesser = num(num<str2num(str))

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by