Knapsack problem/Continuous: Difference between revisions

m
→‎{{header|D}}: minor change
m (→‎{{header|D}}: minor change)
Line 285:
break ;
}
writefln("%10s %7s %7s %7s", "ITEM", "PORTIONAMOUNT", "VALUE", "$/unit") ;
foreach(itm; selects)
writeln(itm) ;
writeflnwriteln(Item("Total weight : %7.2fTOTAL", sum!"amount"(selects), sum!"value"(selects))) ;
writefln("Total value : %7.2f", sum!"value"(selects)) ;
}</lang>
output:
<pre> ITEM PORTION AMOUNT VALUE $/unit
salami 3.00 95.00 31.67
ham 3.60 90.00 25.00
Line 298 ⟶ 297:
greaves 2.40 45.00 18.75
welt 3.50 63.38 18.11
TOTAL 15.00 349.38 23.29</pre>
Total weight : 15.00
 
Total value : 349.38</pre>
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
Anonymous user