how can I print some numbers in ascending order?

조회 수: 8 (최근 30일)
Rahma Sabbah
Rahma Sabbah 2019년 7월 2일
답변: Kaustav Bhattacharya 2019년 7월 2일
a= input('please enter a number:');
b= input('enter second number:');
c= input('enter number:');
I do not know how to print some numbers that user enter in ascending order.
  댓글 수: 3
Star Strider
Star Strider 2019년 7월 2일
Since this sounds like homework, what functions are you allowed to use?
Rahma Sabbah
Rahma Sabbah 2019년 7월 2일
I have a limit to 3 numbers
I am allowed to use for, if and while functions

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

답변 (2개)

Kaustav Bhattacharya
Kaustav Bhattacharya 2019년 7월 2일
You have a, b, c. If you can use >,< then the following implemention can be used.
max = (a>b)*a + (a<b)*b
max = (max>c)*max + (max<c)*c
min = (a>b)*b + (a<b)*a
min = (min>c)*c + (min<c)*min
mid = (max~=a & min~=a)*a + (max~=b & min~=b)*b + (max~=c & min~=c)*c
disp([min,mid,max])

Luna
Luna 2019년 7월 2일

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by