| 04回(11/14) | |
|---|---|
| 3コマ | 40 |
| 4コマ | 44 |
def max(x,y,z)
if x < y # x >= y となるよう値を交換
t = x
x = y
y = t
end
# 以下では必ず x >= y が成立している
if y > z # つまり x >= y > z が成立
return x
# 以下では必ず x >= y かつ z >= y であるから max(x,z) を計算すればよい
elsif x > z
return x
else
return z
end
end
puts max(1,2,3)
def max2(x,y)
if x > y
return x
else
return y
end
end
def max3(x,y,z)
return max2(x, max2(y,z))
end
puts max3(1,2,3)
integer = gets.to_i puts integer
def f(x) return x + x end # def f ... の「終り」 if x > y if y > z ... else ... end # 内側の if 文の「終り」 end # 外側の if 文の「終り」
<pre style="background-color: yellow; color: yellow">黄色</pre>
黄色