How to find max value of three varibles using if,else,end.
Show older comments
The variables are:
a=20
b=10
c=30
How do i find the max without using built in functions.
I believe it is
if a>b && a>c
disp(a)
elseif b>a && b>c
disp(b)
else
disp(c)
end
Accepted Answer
More Answers (2)
siva naga sai babu
on 17 Feb 2021
0 votes
a = 20;
b = 10;
c = 30;
data = [a,b,c];
largest = data(1);
for i = 1:length(data)
if data(i) > largest;
largest = data(i);
end
end
Vallambotla
on 28 Nov 2022
0 votes
a = 20;
b = 10;
c = 30;
data = [a,b,c];
largest = data(1);
for i = 1:length(data)
if data(i) > largest;
largest = data(i);
end
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!