x = [ 3 , 4 , 9 , 6 , 2 ] sum = 0 x.length.times { |i| sum += x[ i ] } printf( "配列xの要素の合計は%dです\n" , sum )