Prev / Next

2007-11-19 / cels2fahr[rubyの勉強][修行]

一番簡単に
cels2fahr-1.rb

def cels2fahr(cels)
  fahr = cels * 9 / 5 + 32
# print("Kashi:",fahr,"\n")
  print("Sesshi:",cels,"\t","Kashi:",fahr,"\n")
end

cels2fahr(3.0)

コマンドラインからデータを入力すると
cels2fahr-2.rb
def cels2fahr(cels)
  fahr = cels * 9 / 5 + 32
  print("Sesshi:",cels,"\t","Kashi:",fahr,"\n")
end

cels = ARGV[0]
p cels
cels2fahr(cels.to_f)

解答はhttp://www.notwork.org/sbcr-ruby/answer/にあるらしい。
4問全部終わったら見てみるか。
どの程度合っていることやら。