MATLAB Answers

0

how can I print some numbers in ascending order?

Asked by Rahma Sabbah on 2 Jul 2019
Latest activity Answered by Kaustav Bhattacharya on 2 Jul 2019
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 Comments

Do you have a limit? How many numbers you want to get from user?
Since this sounds like homework, what functions are you allowed to use?
I have a limit to 3 numbers
I am allowed to use for, if and while functions

Sign in to comment.

2 Answers

Answer by Luna
on 2 Jul 2019

  0 Comments

Sign in to comment.


Answer by Kaustav Bhattacharya on 2 Jul 2019

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])

  0 Comments

Sign in to comment.