how to sort in increasing order using loop?

7 ビュー (過去 30 日間)
baiti
baiti 2017 年 12 月 16 日
回答済み: rohan hazarika 2020 年 9 月 18 日
for i=1:6
A(i)=input('')
end
for i=1:6
for j=1:5
if A(j)>=A(j+1)
B=A(j);
A(j)=A(j+1);
A(j+1)=B;
end
end
end
  6 件のコメント
Jan
Jan 2017 年 12 月 17 日
@baiti: It seems like you have a problem running this code. Then it would be useful, if you mention what the problem is. "it wont work on my matlab" does not allow to reconsider, why you are not satisfied.
Manish Kumar
Manish Kumar 2020 年 6 月 26 日
Do you want better algorithm than this?

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

回答 (1 件)

rohan hazarika
rohan hazarika 2020 年 9 月 18 日
for i=1:6
A(i)=input('')
end
for i=1:6
for j=1:5
if A(j)>=A(j+1)
B=A(j);
A(j)=A(j+1);
A(j+1)=B;
end
end
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by