make different numbers with the same digits

2 ビュー (過去 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
  1 件のコメント
Jens Petit-jean
Jens Petit-jean 2020 年 10 月 19 日
thank you!

サインインしてコメントする。


KSSV
KSSV 2020 年 10 月 19 日
str = '215' ;
num = str2num(perms(str)) ;
greater = num(num>str2num(str))
lesser = num(num<str2num(str))
  1 件のコメント
Jens Petit-jean
Jens Petit-jean 2020 年 10 月 19 日
thank you!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by