#!/usr/koeki/bin/ruby # coding: utf-8 def average(score) # scoreは数値のたくさん入っている配列 sum = 0.0 # 割り算する予定なので浮動小数点数にしておく score.each do |x| sum += x end sum/score.length end points=[] # からっぽの配列を作る i=0 # iがpointsの添字となる while true STDERR.print "数値を入力して下さい: " line=gets if line == nil break end points[i] = line.chomp!.to_i i += 1 end printf("\n平均値は %6.2f です\n", average(points))