Table-Driven Calculations
Weighted Table Total
Row Accumulation
A calculation table can pair values with weights and accumulate row contributions.
Program
Play the program to include more rows in the weighted total.
weighted_table_total.f90
program weighted_table_total_demo
implicit none
integer :: values(3)
integer :: weights(3)
integer :: row_count
integer :: i
integer :: total
integer :: contribution
values = [5, 7, 9]
weights = [2, 3, 4]
row_count =
total = 0
do i = 1, row_count
contribution = values(i) * weights(i)
total = total + contribution
end do
print '(I0, 1X, I0)', row_count, total
end program weighted_table_total_demo
program weighted_table_total_demo
implicit none
integer :: values(3)
integer :: weights(3)
integer :: row_count
integer :: i
integer :: total
integer :: contribution
values = [5, 7, 9]
weights = [2, 3, 4]
row_count =
total = 0
do i = 1, row_count
contribution = values(i) * weights(i)
total = total + contribution
end do
print '(I0, 1X, I0)', row_count, total
end program weighted_table_total_demo
program weighted_table_total_demo
implicit none
integer :: values(3)
integer :: weights(3)
integer :: row_count
integer :: i
integer :: total
integer :: contribution
values = [5, 7, 9]
weights = [2, 3, 4]
row_count =
total = 0
do i = 1, row_count
contribution = values(i) * weights(i)
total = total + contribution
end do
print '(I0, 1X, I0)', row_count, total
end program weighted_table_total_demo
paired columns
`values(i)` and `weights(i)` are matching columns in the same row.
contribution
Each row contribution is calculated before it is added to the total.
partial table
`row_count` lets a calculation use only the active rows.