RESOLVED EXERCISIES
|
PAGE 1 / 6
|
The IF Conditional Statement
REQUIREMENT
Two
different integers are
read from the keyboard. Display
which one is greater.
SOLUTION
Analyze and run the program below:
DETAILS
After reading the two numbers (variables
n and
m), the
if statement is executed.
First, the logical expression is evaluated. In our example, it is
n>m. If the number stored
in variable
n is greater than the one stored in variable
m, the logical expression evaluates to
True
and
n is greater than m is printed. Otherwise, the logical expression evaluates to
False and
m is greater than n is printed.
Since there are no more instructions after
if, the program execution ends.
Analyze the solved problem,
then proceed to the next page.