Info

# New to matlab, in need of help.

1 view (last 30 days)
Rand Renwar on 29 Jan 2016
Closed: MATLAB Answer Bot on 20 Aug 2021
I have to write a program which asks for three different numbers that then shows the three numbers that i wrote and then adds the biggest and the smallest number that i wrote.
Example:
Sum is: 12
So far I've written a program that asks for three different numbers, it looks like this:
That's everything that i have written so far. I'm thinking that i would need to write some 'elses' and 'if's' which commands which of x,y,z is the largest and the smallest.
Thanks!

Ingrid on 29 Jan 2016
it's probably easier if you store the values in one variable, that way you do not need any if-else commands
x = zeros(3,1);
x(1)=input('Write your first number: ') ;
x(2)=input('Write your second number: ') ;
sprintf('Sum is: %1.0f', min(x) + max(x))
##### 2 CommentsShow 1 older commentHide 1 older comment
Ilham Hardy on 29 Jan 2016
Can you use sort()?

Image Analyst on 29 Jan 2016
Hint. Try this:
if x > y && x > z
theMax = x;
elseif y > x && y > z
theMax = y
and so on. Obviously use < instead of > when you want to find the min.