You are on page 1of 4

#write a program that requests three integers from user

# and returns the largest odd integer


#actual exercise is harder with 10 integers
#finger exercise at end of ch. 2 on Guttags second edition
#prob exam question: Distibution of output values?

largest-odd 5 Program output

x= 4 User inputs values, or


y= 8 excel randomly generates int
z= 5

i-x= 0 An index is generated to determine the


i-y= 0 position of each variable in an ordered list
i-z= 0

i-inc-x-1= 0
i-inc-x-2= 0

n-i-x= 0

i-inc-y-1= 1
i-inc-y-2= 1

n-i-y= 2

i-inc-z-1= 1
i-inc-z-2= 0

n-i-z= 1

Indixes
n-i-x= 0
n-i-y= 2
n-i-z= 1

x-odd-index2 0 Index lenght could be 3 if all variables are different, or 2 or 1 if


y-odd-index2 0 This section checks both if the variable is odd and of index 2, 1
z-odd-index2 0

x-odd-index1 0
y-odd-index1 0
z-odd-index1 1
x-odd-index0 0
y-odd-index0 0
z-odd-index0 0

largest-odd 5 Nested ifs to check each group of variables by index.


If a group of variables is zero sums not zero, a variable in the g
and index match is performed to select the biggest variable val
nested if check first for group of variables when index is 2, then
if none of the groups have odd variables with index of the grou
Each variable is initilaized
with index 0

Check if it is greater than other variable


And the other

Index increases one number for each variable it is compared as greater

Variable indexes are grouped together.

are different, or 2 or 1 if numbers repeat


is odd and of index 2, 1 or 0
bles by index.
t zero, a variable in the group is true,
t the biggest variable value within the group
les when index is 2, then if index is 1, then 0
es with index of the group, return is false

You might also like