diff --git a/heikin.rb b/heikin.rb new file mode 100755 index 0000000..746adfc --- /dev/null +++ b/heikin.rb @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +# -*-coding: utf-8 -*- + +def heikin (x, y, z) + wa = x + y + z + return wa/3 +end + +puts heikin(3, 4, 2) diff --git a/hello2.rb b/hello2.rb new file mode 100755 index 0000000..a4bf225 --- /dev/null +++ b/hello2.rb @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +# -*-coding: utf-8 -*- + +def hello2(x) + printf("Hello, %s-san!\n", x) + printf("%sさんこんにちは!\n", x) +end + +hello2("太郎") +hello2("Kate") +hello2("Mike") diff --git a/kakezan.rb b/kakezan.rb new file mode 100755 index 0000000..d9ee3e8 --- /dev/null +++ b/kakezan.rb @@ -0,0 +1,12 @@ +#!/usr/bin/env ruby +# -*-coding: utf-8 -*- + +def kakezan(x, y) + a=x*y + return a +end + +puts "2つ数値を入れてください。掛け算した値を返します。" +x = gets.to_i +y = gets.to_i +printf("%d\n", kakezan(x, y)) diff --git a/shikakkei.rb b/shikakkei.rb index affd4b5..8ad1bfa 100755 --- a/shikakkei.rb +++ b/shikakkei.rb @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- def shikakkei(tate, yoko) - if tate < 0 || yoko < 0 + if tate <= 0 || yoko <= 0 return nil - end + end return tate*yoko end