programming-examples/perl/Statement/Using for loop to sum the total.pl

8 lines
215 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
@a = (1, 2, 3, 4, 5, 6, 7, 8, 9);
$running_sum = 0;
for ($loop_index = 0; $loop_index <= $#a + 1; $loop_index++) {
$running_sum += $a[$loop_index];
}
print "Average value = " . $running_sum / ($#a + 1);