Conditional statements
if
EE 201
C9-1
Spring 2012
1
Class Learning Objectives
Achieve Comprehension LOL of using
Conditional statements in
programming
C9-1
Spring 2012
2
Example: 1
Start
Draw the flowchart and
Flowchart
write a MATLAB
Integer
i
program that reads an
integer ,determines and
Remainder(i/2) ==0
prints whether it is odd
F
T
or even?
Display Even
number
Display Odd
number
End
C9-1
Spring 2012
3
MATLAB
program
Output
C9-1
Spring 2012
4
Example: 2
Draw the flowchart and write a MATLAB
program that reads 3 integers, determines
and prints the biggest?
C9-1
Spring 2012
5
a= input('A= ');
b= input('B= ');
c= input('C= ');
if a >b
if a>c
disp (a);
else
disp(c);
end
else
if b>c
disp(b);
else
disp(c)
end
end
Start
Flowchart
Input
A,B,C
F
A>B
F
T
B>C
A>C
Display
A
T
Display
C
Display
B
Display
C
MATLAB
program
End
C9-1
Spring 2012
OR
a= input('A= ');
b= input('B= ');
c= input('C= ');
if a >b
if a>c
disp (a);
else
disp(c);
end
elseif b>c
disp(b);
else
disp(c)
end
6
Example: 3
Write a MATLAB program that accepts a grade as numerical
value x from 0 to 100 as input and displays the corresponding
letter grade given by the following table:
Numeric grades
Letter grades
x≥90
A
80≤x<90
B
70≤x<80
C
60≤x<70
D
x<60
F
C9-1
Spring 2012
7
Draw Flowchart ????
C9-1
Spring 2012
8
MATLAB
program
Output
C9-1
Spring 2012
9
OR:
MATLAB
program
Output
C9-1
Spring 2012
10
© Copyright 2026 Paperzz