x = [ 3 , 4 , 9 , 6 , 2 ] y = [ 7 , 8 , 3 , 1 , 4 ] sum = 0 x.length.times { |i| sum += x[ i ] * y[ i ] } printf( "xとyの内積は%dです\n" , sum )