Skip to content

Commit b0e5be2

Browse files
committed
add function 9, 10
1 parent de66a77 commit b0e5be2

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

09-function.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# 题目: 使用者输入直角三角形的宽和高,输出三角形的面积
2+
3+
def calculate_area(a, b)
4+
# ....
5+
end
6+
7+
print "请输入直角三角形的高,然后按 Enter: "
8+
a = gets
9+
10+
print "请输入直角三角形的底边,然后按 Enter: "
11+
b = gets
12+
13+
answer = calculate_area(a,b)
14+
15+
puts "直角三角形的面积是: #{answer}"

10-function.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 题目: 使用者输入 x,y,z,请输出三个数中最大的数
2+
3+
def find_max(x, y, z)
4+
end
5+
6+
print "请输入一个数字x,然后按 Enter: "
7+
x = gets
8+
9+
print "请输入一个数字y,然后按 Enter: "
10+
y = gets
11+
12+
print "请输入一个数字z,然后按 Enter: "
13+
z = gets
14+
15+
# ....
16+
17+
answer = find_max(x,y,z)
18+
19+
puts "最大的数是 #{answer}"

0 commit comments

Comments
 (0)