5人の点数を読み込んで合計点と平均点を表示
明解C言語 入門編 > 5. 配列 >
5人の点数を読み込んで合計点と平均点を表示
Ruby
puts "点数を入力してください。" print "1番:" score1 = STDIN.gets.chomp.to_i print "2番:" score2 = STDIN.gets.chomp.to_i print "3番:" score3 = STDIN.gets.chomp.to_i print "4番:" score4 = STDIN.gets.chomp.to_i print "5番:" score5 = STDIN.gets.chomp.to_i sum = 0 sum += score1 sum += score2 sum += score3 sum += score4 sum += score5 print "合計点#{sum}\n" printf("平均点%f\n", sum / 5)
実行結果
L:\>ruby l:\lesson_05_029.rb
点数を入力してください。
1番:95
2番:83
3番:85
4番:63
5番:89
合計点415
平均点83.000000